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
  • 相关阅读:
    hmset
    java 调用mongo 判断大于等于 并且小约等于<=
    Maven项目,别人的没问题,自己机器一直有问题
    linux 时间datetimectl 问题
    真正手把手教 git
    0324-SQLMAP使用参数备注
    安全推荐网址:
    JavaScript Base64 作为文件上传的实例代码解析
    学习笔记|变量的解构赋值
    学习笔记|let 和 const 命令
  • 原文地址:https://www.cnblogs.com/laugh/p/6708800.html
Copyright © 2011-2022 走看看