美文网首页
Core Animation 核心动画

Core Animation 核心动画

作者: dicesc | 来源:发表于2016-07-21 13:38 被阅读13次

layer 实现 (直接修改layer位置,控件会跟着移动)

  1. layer 主要属性 直接修改属性,默认有动画
    1. 圆角 cornerRadius self.button.layer.cornerRadius = 50; 减去阴影效果 layer . masksToBounds = YES
    2. contents 内容 layer.contents = (__brige id _Nullabel) ( image.CGImage ) 也可作为背景设置
    3. 阴影 shadowOpacity shadowOffset shadowRadius
    4. 边框 borderWidth 有动画 向内缩进 borderColor
    5. transform属性
    6. 旋转 CATransform3DRotate (self.layer.transform , M_PI , X ,Y ,Z )
    7. 缩放 CATransform3DScale (self.layer.transform , M_PI , X ,Y ,Z )
    8. 平移 translate
    9. position 和 anchorPoint
      1. position 相对于父layer来说的 位置
      2. anchorPoint 锚点 定位点 相对于自己说的 取值范围 0~1 默认 (0.5 , 0.5 ) 自己的高度 宽度 都乘以 0.5 确定layer 对于父layer的 相对值

核心动画 CorAnimation (对layer添加动画 UIView 不会跟着动画走动)

  • 结构继承
    • CABasicAnimation 基本动画
      • fromValue
      • toValue
      • byValue
    • CAKeyframeAnimation 关键帧动画
    • CAAnimationGroup 组动画 group .animations addAnimation
    • CATransition 转场动画
      • type 主动画
      • subType 子动画
  • 结构图
screenshot.png

实现步骤

  • 实现步骤 ( 一定先 设置属性 再添加 否则 后面的属性无效)
    1. 创建动画对象 anim = [CABasicAnimation aimationWithKeyPath : @“position.y “ ] bounds.size(缩放) transform.rotation.z(旋转)
    2. 设置属性 anim.fromValue = @200 anim. toValue = @500
    3. 添加到对应的layer上 [ self.layer addAnimation : aim forKey nil ] Key: 删除的时候需要用到
    4. 让位置停留 (动画结束会默认 删除)
      • 设置代理 (不需要协议)
      • animationDidStart
      • animationDidStop

相关文章

网友评论

      本文标题:Core Animation 核心动画

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