IOS核心动画

1.CABasicAnimation基础动画



    //1.创建一个动画对象
    CABasicAnimation *animation = [CABasicAnimation animation];
    
    //2.设置属性值
//    animation.keyPath = @"position.x";
    animation.keyPath = @"transform.scale";
    animation.toValue = @0;
    //执行次数
    animation.repeatCount = MAXFLOAT;
    //执行时长
    animation.duration = 3;
    //自动反转
    animation.autoreverses = YES;
    
    
    //动画完成时会自动删除动画
//    animation.removedOnCompletion = NO;
//    animation.fillMode = @"forwards";
    
    //3.添加动画
    [self.redView.layer addAnimation:animation forKey:nil];


2.1CAKeyframeAnimation(帧动画)通过values设置多个值



    CAKeyframeAnimation *animation = [CAKeyframeAnimation animation];
    animation.keyPath = @"transform.rotation";
    //values设置多个值
    animation.values = @[@10, @20, @10];
    animation.repeatCount = MAXFLOAT;
    animation.autoreverses = YES;
    
    
    [self.redView.layer addAnimation:animation forKey:nil];

2.2CAKeyframeAnimation(帧动画)通过path设置多个值





    
    CAKeyframeAnimation *animation = [CAKeyframeAnimation animation];
    animation.keyPath = @"transform.rotation";
    
    //根据路径做动画
    UIBezierPath *path = [UIBezierPath bezierPath];
    [path moveToPoint:CGPointMake(50, 50)];
    [path addLineToPoint:CGPointMake(300, 50)];
    [path addLineToPoint:CGPointMake(300, 400)];
    animation.keyPath = @"position";
    animation.path = path.CGPath;
    
    animation.repeatCount = MAXFLOAT;
    animation.autoreverses = YES;
    
    
    [self.redView.layer addAnimation:animation forKey:nil];

3.CATransition(转场动画)根据type设置不同效果



    CATransition *animation = [CATransition animation];
    
    animation.duration = 1;
    
    //fade', `moveIn', `push' and `reveal'. Defaults to `fade
    // cube-立方体 ,suckEffect-吸走的效果,oglFlip-前后翻转效果rippleEffect-波纹效果
    //pageCurl-翻页 pageUnCurl-翻页 cameraIrisHollowOpen-镜头开 cameraIrisHollowClose 镜头开关
    animation.type = @"cube";
    _redView.backgroundColor = [UIColor redColor];
    [_redView.layer addAnimation:animation forKey:nil];

4.CABasicAnimation(动画组)

 CABasicAnimation *animation1 = [CABasicAnimation animation];
    animation1.keyPath = @"position.y";
    animation1.toValue = @400;
    
    CABasicAnimation *animation2 = [CABasicAnimation animation];
    animation2.keyPath = @"transform.scale";
    animation2.toValue = @0.5;
    
    CAAnimationGroup *group = [CAAnimationGroup animation];
    group.animations = @[animation1, animation2];
    [_redView.layer addAnimation:group forKey:nil];


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值