美文网首页
iOS QuartzCore 动画和Layer层

iOS QuartzCore 动画和Layer层

作者: 移动的键盘 | 来源:发表于2021-02-04 11:39 被阅读0次

    动画

    • CAAnimation<CAMediaTiming, CAAction> 动画基类,不直接调用
    //创建一个动画对象
    + (instancetype)animation;
    //一个计时函数,定义动画的节奏。默认值为nil,表示线性节奏。
    @property(nullable, strong) CAMediaTimingFunction *timingFunction;
    //动画代理,注意此处修饰符为strong,这是iOS内存管理中的特例。代理最常用的修饰符是weak。
    @property(nullable, strong) id <CAAnimationDelegate> delegate;
    
    • CAMediaTimingFunction
    //创建定时函数。目前支持的名称是“linear”,“easeIn”,“easeOut”和“easeInEaseOut”和“default”(由Core Animation创建的隐式动画使用的曲线)。
    + (instancetype)functionWithName:(CAMediaTimingFunctionName)name;
    //线性运动
    kCAMediaTimingFunctionLinear
    //慢入快出
    kCAMediaTimingFunctionEaseIn
    //快入慢出
    kCAMediaTimingFunctionEaseOut
    //慢入慢出
    kCAMediaTimingFunctionEaseInEaseOut
    //默认
    kCAMediaTimingFunctionDefault
    
    • CAAnimationDelegate
    @optional
    //动画开始
    - (void)animationDidStart:(CAAnimation *)anim;
    //动画结束
    - (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag;
    
    • CAMediaTiming 协议
    @property CFTimeInterval beginTime;
    @property CFTimeInterval duration;
    @property float speed;
    @property CFTimeInterval timeOffset;
    @property float repeatCount;
    @property CFTimeInterval repeatDuration;
    @property BOOL autoreverses;
    @property(copy) CAMediaTimingFillMode fillMode;
    
    • CAAction 协议
    - (void)runActionForKey:(NSString *)event object:(id)anObject arguments:(nullable NSDictionary *)dict;
    
    • CAPropertyAnimation 属性动画基类,不直接调用,是CAAnimation的一个子类
    //创建一个属性动画,path指的是layer的属性,哪些属性可作为path,这篇博客总结很全面 [https://blog.csdn.net/qq_42792413/article/details/86506479]
    + (instancetype)animationWithKeyPath:(nullable NSString *)path;
    //可动画的属性
    @property(nullable, copy) NSString *keyPath;
    //该属性指定该属性动画是否以当前动画效果为基础
    @property(getter=isAdditive) BOOL additive;
    //该属性指定动画是否为累加效果
    @property(getter=isCumulative) BOOL cumulative;
    //valueFunction是专门为了transform动画而设置的,因为我们没有办法直接改变transform3D中的属性,通过这个参数,可以帮助我们直接操作transfrom3D属性变化产生动画效果
    @property(nullable, strong) CAValueFunction *valueFunction;
    
    • CAValueFunction
    //创建一个 CAValueFunction
    + (nullable instancetype)functionWithName:(CAValueFunctionName)name;
    //绕X轴旋转
    kCAValueFunctionRotateX
    //绕Y轴旋转
    kCAValueFunctionRotateY
    //绕Z轴旋转
    kCAValueFunctionRotateZ
    //沿X轴缩放
    kCAValueFunctionScaleX
    //沿Y轴缩放
    kCAValueFunctionScaleY
    //沿Z轴缩放
    kCAValueFunctionScaleZ
    //沿X轴平移
    kCAValueFunctionTranslateX
    //沿Y轴平移
    kCAValueFunctionTranslateY
    //沿Z轴平移
    kCAValueFunctionTranslateZ
    //和CATransform3D的对应关系
    CATransform3D{
        rotation旋转
        transform.rotation.x
        transform.rotation.y
        transform.rotation.z
    
        scale缩放
        transform.scale.x
        transform.scale.y
        transform.scale.z
    
        translation平移
        transform.translation.x
        transform.translation.y
        transform.translation.z
    }
    
    • CABasicAnimation 基础动画,依然是属性动画,直接调用,是CAPropertyAnimation 的子类
    //动画起始值,id类型,可是多种类型
    @property(nullable, strong) id fromValue;
    //动画结束值
    @property(nullable, strong) id toValue;
    //动画相对起始值的变化
    @property(nullable, strong) id byValue;
    //举例,修改背景色
    CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"backgroundColor"];
    anim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    anim.fromValue = (id)[UIColor redColor].CGColor;
    anim.toValue = (id)[UIColor greenColor].CGColor; anim.duration = 1.0;
    anim.repeatCount = 1;
    anim.removedOnCompletion = NO;
    anim.fillMode = kCAFillModeForwards;
    [layer addAnimation:anim forKey:@"bColor"];
    

    持续更新...

    相关文章

      网友评论

          本文标题:iOS QuartzCore 动画和Layer层

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