Core Animation

2021-03-02  本文已影响0人  Fat_Blog
image.png

CAKeyframeAnimation

 CAKeyframeAnimation *anim = [CAKeyframeAnimation animation];
    anim.keyPath = @"position";
    //贝塞尔曲线
    UIBezierPath *path = [UIBezierPath bezierPath];
    //起点
    [path moveToPoint:CGPointMake(50, 50)];
    //连线
    [path addLineToPoint:CGPointMake(300, 50)];
    anim.duration = 0.5;
    //动画保持最后一个状态
    anim.fillMode = kCAFillModeForwards;
    anim.path = path.CGPath;
    //动画执行完不会被自动删除
    anim.removedOnCompletion = NO;
    [self.imageV.layer addAnimation:anim forKey:nil];
CAKeyframeAnimation *anim = [CAKeyframeAnimation animation];
    anim.keyPath = @"transform.rotation";
    anim.values = @[@angleZRad(-5),@angleZRad(5)];
    //自动反转
    anim.autoreverses = YES;
    anim.repeatCount = MAXFLOAT;
    [self.imageV.layer addAnimation:anim forKey:nil];

CABasicAnimation

CABasicAnimation *anim = [CABasicAnimation animation];
    anim.keyPath = @"transform.scale";
    anim.toValue = @0;
    anim.duration = 1;
    //设置自动反转
    anim.autoreverses = YES;
    //设置动画无线执行
    anim.repeatCount = MAXFLOAT;
    [self.imageView.layer addAnimation:anim forKey:nil];

CATransition

  • fade
    交叉淡化过渡
    不支持过渡方向
    对应的常量为kCATransitionFade
 //转场代码跟转场动画必须连在一起
    CATransition *anim = [CATransition animation];
    anim.type = @"push";
    self.i++;
    NSString *image = [NSString stringWithFormat:@"%d",self.i];
    self.imageV.image = [UIImage imageNamed:image];
    [self.imageV.layer addAnimation:anim forKey:nil];

CAAnimationGroup

CABasicAnimation *anim = [CABasicAnimation animation];
    anim.keyPath = @"position.y";
    anim.toValue = @400;
    
    CABasicAnimation *anim2 = [CABasicAnimation animation];
    anim2.keyPath = @"transform.scale";
    anim2.toValue = @0.5;
    
    CAAnimationGroup *group = [CAAnimationGroup animation];
    group.animations = @[anim,anim2];
    group.removedOnCompletion = NO;
    group.fillMode = kCAFillModeForwards;
    
    [self.imageV.layer addAnimation:group forKey:nil];

UIView动画跟核心动画的区别

什么时候选择核心动画

demo https://github.com/KK177/Animation

上一篇下一篇

猜你喜欢

热点阅读