美文网首页
核心动画

核心动画

作者: 晶宝的小花园 | 来源:发表于2017-02-17 14:13 被阅读0次
//
//  ViewController.m
//  core
//
//  Created by chenvinci on 2017/2/16.
//  Copyright © 2017年 cuijing. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIView *redView;
@property (weak, nonatomic) IBOutlet UIImageView *img;

@property(nonatomic) int iIndex;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
   
    self.iIndex = 0;
    
    self.redView.layer.anchorPoint = CGPointMake(0, 0);
    self.redView.layer.position = CGPointMake(100, 100);

}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    
    //平移动画
    CABasicAnimation * moveA = [[CABasicAnimation alloc]init];
    moveA.keyPath = @"position";
    moveA.byValue = [NSValue valueWithCGPoint:CGPointMake(50, 50)];//每次移动(50,50)
    
    //bounds动画
    CABasicAnimation * boundA = [CABasicAnimation animation];
    boundA.keyPath = @"bounds";
    boundA.toValue = [NSValue valueWithCGRect:CGRectMake(0, 0, 40, 40)];
    
    //创建组动画
    CAAnimationGroup*group = [CAAnimationGroup animation];
    
    group.animations = @[moveA,boundA];
    group.duration = 3;
    
    //动画完成时不动
    group.removedOnCompletion = NO;
    group.fillMode = kCAFillModeForwards;
    
    //添加动画
    [self.img.layer addAnimation:group forKey:nil];
}

-(void)touchesBegan3:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    //创建转场动画
    CATransition* animation1 = [CATransition animation];

    NSArray* arr = @[@"cube",@"moveIn",@"reveal",@"pageCurl",@"suckEffect",@"rippleEffect",@"oglFlip"];
    
    if (self.iIndex >= arr.count) {
        self.iIndex = 0;
    }
    
    animation1.type = arr[self.iIndex];
    animation1.subtype = @"fromTop";
    
    self.iIndex++;
    
    
    
    //添加动画
    [self.img.layer addAnimation:animation1 forKey:nil];
}

-(void)touchesBegan2:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    
    //创建关键帧动画
    CAKeyframeAnimation*animation1 = [[CAKeyframeAnimation alloc]init];
    
    animation1.duration = 4;
    
    //设置动画属性  修改position
    animation1.keyPath = @"position";
    
    NSValue*v1 = [NSValue valueWithCGPoint:CGPointMake(0, 0)];
    NSValue*v2 = [NSValue valueWithCGPoint:CGPointMake(100, 0)];
    NSValue*v3 = [NSValue valueWithCGPoint:CGPointMake(100, 100)];
    NSValue*v4 = [NSValue valueWithCGPoint:CGPointMake(0, 100)];
    NSValue*v5 = [NSValue valueWithCGPoint:CGPointMake(0, 0)];
    
    animation1.values = @[v1,v2,v3,v4,v5];
    
    //设置各关键帧的时间
    NSNumber*t1 = [NSNumber numberWithFloat:0.1];//最大是1
    NSNumber*t2 = [NSNumber numberWithFloat:0.2];
    NSNumber*t3 = [NSNumber numberWithFloat:0.8];
    NSNumber*t4 = [NSNumber numberWithFloat:0.9];
    NSNumber*t5 = [NSNumber numberWithFloat:1.0];
    
    animation1.keyTimes = @[t1,t2,t3,t4,t5];
    
    //动画执行完以后是否移除?
    animation1.removedOnCompletion = NO;
    animation1.fillMode = kCAFillModeForwards;//保持最新状态
    
    
    // 添加动画
    [self.redView.layer addAnimation:animation1 forKey:nil];
}

-(void)touchesBegan1:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    
    //创建基础动画
    CABasicAnimation* animation1 = [[CABasicAnimation alloc]init];
    
    //设置动画属性  修改bounds
    animation1.keyPath = @"bounds";//改bounds属性要去掉autolayout
    animation1.fromValue = [NSValue valueWithCGRect:CGRectMake(0, 0, 100, 100)];
    animation1.toValue = [NSValue valueWithCGRect:CGRectMake(0, 0, 200, 200)];
    
    
    //设置动画属性  修改position
    animation1.keyPath = @"position";
    animation1.fromValue = [NSValue valueWithCGPoint:CGPointMake(0, 0)];
    animation1.toValue = [NSValue valueWithCGPoint:CGPointMake(100, 100)];
    
    
    //设置动画属性  修改transform
    animation1.keyPath = @"transform.translation.x";
    animation1.fromValue = [NSNumber numberWithInt:20];
    animation1.toValue = [NSNumber numberWithInt:50];
    
    
    //设置代理
    animation1.delegate = self;
    
    //设置时长
    animation1.duration = 2;
    
    //动画执行完以后是否移除?
    animation1.removedOnCompletion = NO;
    animation1.fillMode = kCAFillModeForwards;//保持最新状态
    // 添加动画
    [self.redView.layer addAnimation:animation1 forKey:nil];
    
    
}

- (void)animationDidStart:(CAAnimation *)anim{
    NSLog(@"start");
}

- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag{
    NSLog(@"stop");
}


@end

相关文章

  • IOS 核心动画CoreAniamation总结

    iOS 核心动画是基于CALayer层的动画,UIView动画是系统对核心动画的封装,核心动画相对UIView来说...

  • iOS基础 - 核心动画(转)

    iOS基础 - 核心动画 一、核心动画 l核心动画基本概念 l基本动画 l关键帧动画 l动画组 l转场动画 lCo...

  • iOS核心动画高级技巧 - 8

    iOS核心动画高级技巧 - 1iOS核心动画高级技巧 - 2iOS核心动画高级技巧 - 3iOS核心动画高级技巧 ...

  • iOS动画(Core Animation)

    1.核心动画(Core Animation):强大的动画API 核心动画所在的位置如下图 核心动画位于UIKit的...

  • IOS 常用动画的实现方式整理

    一、CoreAnimation(核心动画) 1.核心动画介绍 1.什么是核心动画 Core Animation可以...

  • UIview动画和核心动画的区别

    UIView和核心动画的区别 核心动画只能添加到CALayer,UIView没有办法使用核心动画 核心动画一切都是...

  • iOS-核心动画

    前言:核心动画的基础知识,包括基本动画、帧动画、转场动画相关知识。 一、核心动画(Core Animation) ...

  • iOS面试个人总结(1)

    动画 1.UIView动画与核心动画的区别? 核心动画只作用在layer. 核心动画修改的值都是假像.它的真实位置...

  • 再来看看动画

    动画一般有:UIKit动画和CoreAnimation(核心)动画 下面主要是核心动画的内容:http://www...

  • 一头扎进iOS核心动画(一)

    记录一下学习的笔记 核心动画 核心动画基本概念 基本动画 关键帧动画 动画组 转场动画 Core Animatio...

网友评论

      本文标题:核心动画

      本文链接:https://www.haomeiwen.com/subject/xztlwttx.html