zoukankan      html  css  js  c++  java
  • 核心动画09-CATransition转场动画

    //  ViewController.m
    //  09-CATransition转场动画
    #import "ViewController.h"
    
    @interface ViewController ()
    @property (weak, nonatomic) IBOutlet UIImageView *imageView;
    
    @end
    
    @implementation ViewController
    static int i = 2;
    
    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
    {
        
        // 转场代码
        if (i == 4) {
            i = 1;
        }
        // 加载图片名称
        NSString *imageN = [NSString stringWithFormat:@"%d",i];
        
        _imageView.image = [UIImage imageNamed:imageN];
        
        i++;
        
        // 转场动画
        CATransition *anim = [CATransition animation];
        
        anim.type = @"pageCurl";
        
        anim.duration = 2;
        
        [_imageView.layer addAnimation:anim forKey:nil];
        
    }
    
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        // Do any additional setup after loading the view, typically from a nib.
    }
    
    - (void)didReceiveMemoryWarning {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }
    
    @end

    10-动画组(了解)

    //  ViewController.m
    //  10-动画组(了解)
    #import "ViewController.h"
    
    @interface ViewController ()
    @property (weak, nonatomic) IBOutlet UIView *redView;
    
    @end
    
    @implementation ViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        // Do any additional setup after loading the view, typically from a nib.
    }
    
    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
    {
        // 同时缩放,平移,旋转
        CAAnimationGroup *group = [CAAnimationGroup animation];
        
        CABasicAnimation *scale = [CABasicAnimation animation];
        scale.keyPath = @"transform.scale";
        scale.toValue = @0.5;
        
        CABasicAnimation *rotation = [CABasicAnimation animation];
        rotation.keyPath = @"transform.rotation";
        rotation.toValue = @(arc4random_uniform(M_PI));
        
        CABasicAnimation *position = [CABasicAnimation animation];
        position.keyPath = @"position";
        position.toValue = [NSValue valueWithCGPoint:CGPointMake(arc4random_uniform(200), arc4random_uniform(200))];
        
        group.animations = @[scale,rotation,position];
        
        [_redView.layer addAnimation:group forKey:nil];
        
        
    }
    
    - (void)didReceiveMemoryWarning {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }
    
    @end

    11-UIView和核心动画区别

    //
    //  ViewController.m
    //  10-UIView和核心动画区别
    //
    //  Created by xiaomage on 15/6/23.
    //  Copyright (c) 2015年 xiaomage. All rights reserved.
    //
    
    #import "ViewController.h"
    
    @interface ViewController ()
    @property (weak, nonatomic) IBOutlet UIView *redView;
    
    @end
    
    @implementation ViewController
    
    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
    {
    //    CABasicAnimation *anim = [CABasicAnimation animation];
    //    
    //    anim.keyPath = @"position";
    //    
    //    anim.toValue = [NSValue valueWithCGPoint:CGPointMake(150, 400)];
    //    
    //    // 注意:取消反弹代码必须放在图层添加动画之前。
    //    anim.removedOnCompletion = NO;
    //    
    //    anim.fillMode = kCAFillModeForwards;
    //    
    //    anim.delegate = self;
    //    
    //    [_redView.layer addAnimation:anim forKey:nil];
        
        [UIView animateWithDuration:0.25 animations:^{
            
            _redView.layer.position = CGPointMake(150, 400);
        }
                         completion:^(BOOL finished) {
                NSLog(@"%@", NSStringFromCGPoint(_redView.layer.position));
            }];
        
        
    }
    
    // 注意:核心动画一切都是假象,并不会真实的改变图层的属性值,如果以后做动画的时候,不需要与用户交互,通常用核心动画(转场)。
    
    // UIView动画必须通过修改属性的真实值,才有动画效果。
    
    // 动画完成的时候调用
    - (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag
    {
        NSLog(@"%@", NSStringFromCGPoint(_redView.layer.position));
    }
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        // Do any additional setup after loading the view, typically from a nib.
        
         NSLog(@"%@", NSStringFromCGPoint(_redView.layer.position));
    }
    
    - (void)didReceiveMemoryWarning {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }
    
    @end
  • 相关阅读:
    微信小程序实现课程表实例
    探索Java中的网络编程技术
    Java中的Spring MVC简介笔记
    我没有想赢,我只是不想输
    下次路过,人间再无我。
    从零基础入门MySQL数据库基础课
    vue.js-详解三大流行框架VUE_快速进阶前端大咖-Vue基础
    学习网站/实用工具,收藏的快搜网站,想找什么都有!!!
    【灵魂拷问】你真的懂得Mysql的管理和使用吗?
    【领会要领】web前端-轻量级框架应用(jQuery基础)
  • 原文地址:https://www.cnblogs.com/laugh/p/6708800.html
Copyright © 2011-2022 走看看