美文网首页
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层

    动画 CAAnimation 动画基类,不直接调用 CAMedi...

  • layer动画和动画委托的实现

    layer动画的实现 layer动画就是层动画,工作原理和视图动画相同。在开始或者是结束时间改变la ye r的属...

  • CALayer上动画的暂停和恢复

    iOS10自带了暂停动画的方法 在iOS10以下 需要自己实现 1.暂停layer动画 2.恢复layer上的动画

  • CoreAnimation 理解

    隐式动画的理解: 1,layer层的动画都伴随着一个隐式动画(默认0.25秒的动画,例子:通过layer 层更改一...

  • Swift-UIView动画

    iOS 中实现动画有好几种方式,UIView 是最简单的一种。UIView 层面的动画只是对 layer 层部分属...

  • 第一篇:CALayer基础知识

    参考书籍:iOS核心动画 我们打开QuartzCore框架的QuartzCore.h文件会发现其中只包含了 一个头...

  • iOS核心动画

    一、关于核心动画的介绍 1、核心动画作用于layer层, layer有两个属性Position和achroPoin...

  • IOS 动画

    动画 Animation CALayer是动画产生的地方,当将动画添加到Layer层的时候,不能直接修改layer...

  • iOS Core Animation全手册

    Core Animation——动画类族,它属于QuartzCore框架的一部分,iOS & OS X图形渲染和动...

  • 《iOS动画》读书笔记·内容层动画

    《iOS动画》读书笔记·前序《iOS动画》读书笔记·显示层动画《iOS动画》读书笔记·内容层动画《iOS动画》读书...

网友评论

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

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