CALayer的动画创建

动画的创建方法
1: CATransition

// 设定动画类型

// 设定动画类型

// kCATransitionFade 淡化

// kCATransitionPush 推挤

// kCATransitionReveal 揭开

// kCATransitionMoveIn 覆盖


// @"cube" 立方体

// @"suckEffect" 吸收

// @"oglFlip" 翻转

// @"rippleEffect" 波纹

// @"pageCurl" 翻页

// @"pageUnCurl" 反翻页

// @"cameraIrisHollowOpen" 镜头开

// @"cameraIrisHollowClose" 镜头关


- (void)viewDidLoad

{

    [super viewDidLoad];

// Do any additional setup after loading the view.

    self.aLayer = [CALayer layer];

    self.aLayer.frame = CGRectMake(2020280300);

    self.aLayer.backgroundColor = [UIColor grayColor].CGColor;

    [self.view.layer addSublayer:self.aLayer];

    

    self.bLayer = [CALayer layer];

    self.bLayer.frame = CGRectMake(40404040);

    self.bLayer.backgroundColor = [UIColor redColor].CGColor;

    [self.aLayer addSublayer:self.bLayer];

    

    self.cLayer = [CALayer layer];

    self.cLayer.frame = CGRectMake(80804040);

    self.cLayer.backgroundColor = [UIColor blueColor].CGColor;

    

    UIButton * button = [UIButton buttonWithType:UIButtonTypeRoundedRect];

    button.frame = CGRectMake(10030010044);

    [button addTarget:self action:@selector(tapButton) forControlEvents:UIControlEventTouchUpInside];

    [self.view addSubview:button];

    

}

-(void)tapButton

{

    CATransition * transition = [CATransition animation];

    transition.duration = 3;

    transition.type = @"cube";

    transition.subtype = kCATransitionFromRight;

    SecondViewController * sec = [[SecondViewController alloc]init];

    

    [self.navigationController pushViewController:sec animated:NO];

    

    [self.navigationController.view.layer addAnimation:transition forKey:nil];


}


2: // 多种动画同时运行

-(void)tapButton3

{

    CAAnimationGroup * group = [CAAnimationGroup animation];

    group.duration = 5;

    

    NSMutableArray * arr = [NSMutableArray arrayWithCapacity:2];

    

    CABasicAnimation * transformA = [CABasicAnimation animationWithKeyPath:@"transform"];

   // transformA.duration = 3;

    

    CATransform3D start = self.aLayer.transform;

    transformA.fromValue = [NSValue valueWithCATransform3D:start];

    

     CATransform3D end = CATransform3DTranslate(start, 1001000);


    transformA.toValue = [NSValue valueWithCATransform3D:end];

    [arr addObject:transformA];

    

    CABasicAnimation * bgColor = [CABasicAnimation animationWithKeyPath:@"backgroundColor"];

    bgColor.fromValue = (__bridge id)(self.aLayer.backgroundColor);

    bgColor.toValue = (__bridge id)([UIColor blueColor].CGColor);

    

    [arr addObject:bgColor];

    

    

    group.animations = arr;

    

    [self.aLayer addAnimation:group forKey:nil];

    

}

//图像沿贝塞尔曲线移动

-(void)tapButton2

{

    CAKeyframeAnimation * positionK = [CAKeyframeAnimation animationWithKeyPath:@"position"];

    positionK.duration = 5;

    //创建一个圆形路径

    UIBezierPath * path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(4040200200)];

    positionK.path = path.CGPath;

    [self.aLayer addAnimation:positionK forKey:nil];


}

//图像的移动

-(void)tapButton1

{

    CAKeyframeAnimation * positionK = [CAKeyframeAnimation animationWithKeyPath:@"position"];

    positionK.duration = 10;

    

    NSMutableArray * values = [NSMutableArray arrayWithCapacity:5];

    

    CGPoint start = self.aLayer.position;

    [values addObject:[NSValue valueWithCGPoint:start]];

    CGPoint point1 = start;

    point1.x += 200;

    [values addObject:[NSValue valueWithCGPoint:point1]];

    CGPoint point2 = point1;

    point2.y += 200;

    [values addObject:[NSValue valueWithCGPoint:point2]];

    

    CGPoint point3 = point2;

    point3.x -= 200;

    [values addObject:[NSValue valueWithCGPoint:point3]];

    

    CGPoint end = point3;

    end.y -= 200;

    [values addObject:[NSValue valueWithCGPoint:end]];

    

    positionK.values = values;


    //数组里面元素是NSNumber类型,而且值为0-1之间,递增,

    //每两个值之间的差值为动画时间比例

    positionK.keyTimes = [NSArray arrayWithObjects:@0,@0.1,@0.4,@0.5,@1nil];


    [self.aLayer addAnimation:positionK forKey:nil];

    

}

-(void)tapButton

{

    CABasicAnimation * positionA = [CABasicAnimation animationWithKeyPath:@"transform"];

    positionA.duration = 3;

    

    CATransform3D start = self.aLayer.transform;

    positionA.fromValue = [NSValue valueWithCATransform3D:start];

    

   CATransform3D end = CATransform3DRotate(start, 3.14100);

    positionA.toValue = [NSValue valueWithCATransform3D:end];

    

    [self.aLayer addAnimation:positionA forKey:nil];


}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值