iOS动画(一)

144 阅读1分钟

小知识,大挑战!本文正在参与“程序员必备小知识”创作活动

本文同时参与「掘力星计划」,赢取创作大礼包,挑战创作激励金

通过问题看本质!!!

View在动画中Frame的变化

1---1.png 位置A移动到位置B,动画过程中视图的坐标变化?

通过displayLink打印得到一直都是 {100,0}

1---2.png 通过displayLink打印view.layer.presentationLayer的坐标,可实时获取动画中的坐标

1---3.png

  • 当动画中设置view.center = CGPointMake(100, 0)的时候,只是对M赋值
  • P只负责显示,M只负责数据的存储和获取
  • P将在每一次屏幕刷新的时候回到M的状态

M是layer本身 P是一个方法,请求的时候返回的对象当前显示在屏幕上的状态的副本

CALayer的属性被标记为Animatable,代表对它赋值可以产生隐式动画。

/** Geometry and layer hierarchy properties. **/
/* The bounds of the layer. Defaults to CGRectZero. Animatable. */
@property CGRect bounds;

/* The position in the superlayer that the anchor point of the layer's
 * bounds rect is aligned to. Defaults to the zero point. Animatable. */
@property CGPoint position;

Layer隐式动画

actionForLayer:forKey:

  • 返回nil,layer会走自己的隐式动画
  • 返回NSNull,无动画
  • 返回CAAction协议的对象,执行动画 UIView持有一个主CALayer,那么这个layer的delegate就是这个view,返回NSNull

Layer显式动画

对一些属性做指定的自定义动画,或者创建非线性动画

  • 基础动画(CABaseAnimation)
  • 动画组(CAAnimationGroup)
  • 过渡动画(CATransition)自带转场动画函数
  • 弹簧动画(CASpringAnimation)9.0 弹簧动画

1----4.png