iOS Core Animation 核心动画

Core Animation

关于核心动画,如果想深入了解可以阅读《iOS核心动画高级技巧》这本书。所有复杂的动画都可以拆分成简单动画(对应路径的单一动画)的组合,这里仅对常用动画的使用做简单梳理。

动画的三步骤:

  • 1、初始化动画
  • 2、修改动画路径Keypath
  • 3、将动画加到对应的layer上
«CAAnimationDelegate» CAAnimation @keypath +animation() CATransition @type 保持到最后: @removeOnCompletion = NO; @fillMode = kCAFillModeForwards; -push() -pop() -present() -dissmiss() -custom() CAAnimationGroup @animations CAPropertyAnimation @keyPath +animationWithKeyPath:(path) CABasicAnimation @fromValue; @toValue; @keyPath=@"position.y"; @toValue = @400; @removeOnCompletion = YES;default @fillMode = kCAFillModeForwards; CAKeyFrameAnimation @path @value:弧度 @speed @repeatCount @duration @Keypath @autoReverse @rotationMode

CALayer 和 UIView的关系

UIView继承与UIResponder, 其实是个交互类,其属性CALayer才是用于显示的。CALayer所属框架QuartzCore,是跨平台的(iOS、MacOS)显示框架。而UIKit和AppKit框架则是两个平台的不同交互框架,分别响应触摸或鼠标键盘事件对不同的UIView做出响应展示在对应的CALayer上。

UIView @center @bounce @frame @layer-->CALayer +animateWithDuration() CALayer @path->UIBezierPath -addAnimation: forKey:()

CABasicAnimation基础动画

  • 你看到的都是假象,真正的view是没有发生变化的
  • postition:(layer里面设置中心点) center:uiview
    锚点:1.概念;2.单位坐标0-1;3.和position的关系:就是锚点在父视图的位置
  • presentationLayer和modelLayer(呈现层和模型层)

隐式动画

  • 隐式动画:默认时间0.25s(位置,颜色,大小),必须是独立的layer才有隐式动画,uiview(根layer) 隐式动画一直存在,如需关闭需设置;隐式动画是系统框架自动完成的。Core Animation在每个runloop周期中自动开始一次新的事务,即使你不显式的用[CATransaction begin]开始一次事务,任何在一次runloop循环中属性的改变都会被集中起来,然后做一次0.25秒的动画。隐式动画是指通过UIView的animateWithDuration:animations:方法创建的动画。在iOS4+,苹果对UIView添加了一种基于block的动画方法:+animateWithDuration:animations:。这样写对做一堆的属性动画在语法上会更加简单,但实质上它们都是在做同样的事情。CATransaction的+begin和+commit方法在+animateWithDuration:animations:内部自动调用,这样block中所有属性的改变都会被事务所包含。

显式动画

  • 显示动画:显式动画是不存在,如需显示要开启(创建)。显式动画是指用户自己通过beginAnimations:context:和commitAnimations:创建的动画。

CAKeyFrameAnimation 关键帧动画

You create a CAKeyframeAnimation object using the inherited animationWithKeyPath: method, specifying the key path of the property that you want to animate on the layer. You can then specify the keyframe values to use to control the timing and animation behavior.

For most types of animations, you specify the keyframe values using the values and keyTimes properties. During the animation, Core Animation generates intermediate values by interpolating between the values you provide. When animating a value that is a coordinate point, such as the layer’s position, you can specify a path for that point to follow instead of individual values. The pacing of the animation is controlled by the timing information you provide.

CATransition 转场动画

You can transition between a layer’s states by creating and adding a CATransition object to it. The default transition is a cross fade, but you can specify different effects from a set of predefined transitions.

CAAnimationGroup 动画组

The grouped animations run in the time space specified by the CAAnimationGroup instance.

The duration of the grouped animations are not scaled to the duration of their CAAnimationGroup. Instead, the animations are clipped to the duration of the animation group. For example, a 10 second animation grouped within an animation group with a duration of 5 seconds displays only the first 5 seconds of the animation.

Important
The delegate and removedOnCompletion properties of animations in the animations array are currently ignored. The CAAnimationGroup delegate does receive these messages.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

群野

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值