动画层内容
来源:互联网 发布:矩阵防御 编辑:程序博客网 时间:2024/05/17 06:45
Listing 3-1 Animating a change implicitly
Customizing the Timing of an Animation.
Listing 3-3 shows the code used to implement the animation in Figure 3-1. The path object in this example is used to define the position of the layer for each frame of the animation.
Listing 3-3 Creating a bounce keyframe animation
// create a CGPath that implements two arcs (a bounce)
CGMutablePathRef thePath = CGPathCreateMutable();
CGPathMoveToPoint(thePath,NULL,74.0,74.0);
CGPathAddCurveToPoint(thePath,NULL,74.0,500.0,
320.0,500.0,
320.0,74.0);
CGRect
(such as the bounds and frame properties), wrap each rectangle in an NSValue
object.- For the layer’s transform property, wrap each
CATransform3D
matrix in anNSValue
object. Animating this property causes the keyframe animation to apply each transform matrix to the layer in turn. - 对于一个层的transform属性,包裹每一个CATransform3D矩阵在一个NSValue对象里面 。动画这个属性使关键帧动画应用到每一个transform matrix
- For the
borderColor
property, cast eachCGColorRef
data type to the typeid
before adding it to the array.
- For properties that take a
CGFloat
value, wrap each value in anNSNumber
object before adding it to the array.
- When animating the layer’s
contents
property, specify an array ofCGImageRef
data types. - 当动画一个层的contents属性的时候, 赋值一个 CGImageRef数据类型的数组。
CGPoint
data type, you can create an array of points (wrapped in NSValue
objects) or you can use aCGPathRef
object to specify the path to follow. When you specify an array of points, the keyframe animation object draws aCGPathRef
object, the animation starts- The
calculationMode
property defines the algorithm to use in calculating the animation timing. The value of this property affects how the other timing-related properties are used. - calculationMode属性定义了用来计算动画时间的算法。这个属性的值影响其他时间相关属性的使用
- Linear and cubic animations—that is, animations where the
calculationMode
property is set tokCAAnimationLinear
orkCAAnimationCubic
—use the provided timing information to generate the animation. These modes give you the maximum control over the animation timing. - 线性的和立方形动画 - 就是, calculationMode属性被设置为KCAnimationLinear或者KCAAnimationCubic—用提供时间信息来生成动画。这些方法给你最大的控制,通过动画timing
- Paced animations—that is, animations where the
calculationMode
property is set tokCAAnimationPaced
orkCAAnimationCubicPaced
—do not rely on the external timing values provided by thekeyTimes
ortimingFunctions
properties. Instead, timing values are calculated implicitly to provide the animation with a constant velocity.
- 节奏动画—就是,属性本设置为KCAAnimationPaced或者KCAAnimationCubicPaced的动画 — 不依赖通过KeyTimes或者timingFunctions属性提供的外在的timing Values.相反, timing values 被隐式的计算来,提供给动画固定的速度。
- Discrete animations—that is, animations where the
calculationMode
property is set tokCAAnimationDiscrete
—cause the animated property to jump from one keyframe value to the next without any interpolation. This calculation mode uses the values in thekeyTimes
property but ignores thetimingFunctions
property - 分离动画—就是, caculationModel被设置为KCAAnimationDiscrete属性的动画— 引起动画属性 从一个帧调到下一帧不带任何的插入。
- 这种计算模式用keyTimes属性提供的值但是忽略timingFunction属性
The
keyTimes
property specifies time markers at which to apply each keyframe value. This property is used only if the calculation mode is set tokCAAnimationLinear
,kCAAnimationDiscrete
, orkCAAnimationCubic
. It is not used for paced animations.- The
timingFunctions
property specifies the timing curves to use for each keyframe segment. (This property replaces the inheritedtimingFunction
property.)
kCAAnimationLinear
or kCAAnimationCubic
mode and the keyTimes
and timingFunctions
properties. The keyTimes
defines the points in time at which to apply each keyframe value. The timing for all intermediate values is controlled by the timing functions, which allow you to apply ease-in or ease-out curves to each segment. If you do not specify any timing functions, the timing is linear.- To remove a single animation object from the layer, call the layer’s
removeAnimationForKey:
method to remove your animation object. This method uses the key that was passed to theaddAnimation:forKey:
method to identify the animation. The key you specify must not benil
.
- To remove all animation objects from the layer, call the layer’s
removeAllAnimations
method. This method removes all ongoing animations immediately and redraws the layer using its current state information.
CAAnimationGroup
object. Using a group object simplifies the management of multiple animation objects by providing a single configuration point. Timing and duration values applied to the group override those same values in the individual animation objects.Listing 3-4 Animating two animations together
// Animation 1
CAKeyframeAnimation* widthAnim = [CAKeyframeAnimation animationWithKeyPath:@"borderWidth"];
NSArray* widthValues = [NSArray arrayWithObjects:@1.0, @10.0, @5.0, @30.0, @0.5, @15.0, @2.0, @50.0, @0.0, nil];
widthAnim.values = widthValues;
widthAnim.calculationMode = kCAAnimationPaced;
// Animation 2
CAKeyframeAnimation* colorAnim = [CAKeyframeAnimation animationWithKeyPath:@"borderColor"];
NSArray* colorValues = [NSArray arrayWithObjects:(id)[UIColor greenColor].CGColor,
(id)[UIColor redColor].CGColor, (id)[UIColor blueColor].CGColor, nil];
colorAnim.values = colorValues;
colorAnim.calculationMode = kCAAnimationPaced;
// Animation group
CAAnimationGroup* group = [CAAnimationGroup animation];
group.animations = [NSArray arrayWithObjects:colorAnim, widthAnim, nil];
group.duration = 5.0;
[myLayer addAnimation:group forKey:@"BorderChanges"];
- Add a completion block to the current transaction using the
setCompletionBlock:
method. When all of the animations in the transaction finish, the transaction executes your completion block.
- Assign a delegate to your
CAAnimation
object and implement theanimationDidStart:
andanimationDidStop:finished:
delegate methods.
beginTime
property of your animation objects to start each one at the desired time. To chain two animations together, set the start time of the second animation to the end time of the first animation. For more information about animation and timing values, see Customizing the Timing of an Animation.UIView
class itself derives most of its data from the layer objectUIView
interfaces to make your changes.UIView
class disables layer animations by default but reenables them inside animation blocks. So any changes you make outside of an animation block are not animated. Listing 3-5 shows an example of how to change a layer’s opacity implicitly and its position explicitly. In this example, the myNewPosition
variable is calculated beforehand and captured by the block. Both animations start at the same time but the opacity animation runs with the default timing while the position animation runs with the timing specified in its animation object.Listing 3-5 Animating a layer attached to an iOS view
[UIView animateWithDuration:1.0 animations:^{
// Change the opacity implicitly.
myView.layer.opacity = 0.0;
// Change the position explicitly.
CABasicAnimation* theAnim = [CABasicAnimation animationWithKeyPath:@"position"];
theAnim.fromValue = [NSValue valueWithCGPoint:myView.layer.position];
theAnim.toValue = [NSValue valueWithCGPoint:myNewPosition];
theAnim.duration = 3.0;
[myView.layer addAnimation:theAnim forKey:@"AnimateFrame"];
}];
Rules for Modifying Layers in OS X
To animate changes to a layer-backed view in OS X, it is best to use the interfaces of the view itself. You should rarely, if ever, directly modify the layer that is attached to one of your layer-backed NSView
objects. AppKit is responsible for creating and configuring those layer objects and for managing them while your app is running. Modifying the layer could cause it to get out of sync with the view object and could lead to unexpected results. For layer-backed views, your code must absolutely not modify any the following properties of the layer object:
anchorPoint
bounds
compositingFilter
filters
frame
geometryFlipped
hidden
position
shadowColor
shadowOffset
shadowOpacity
shadowRadius
transform
Important: The preceding restrictions do not apply to layer-hosting views. If you created the layer object and associated it with a view manually, you are responsible for modifying the properties of that layer and keeping the corresponding view object in sync.
AppKit disables implicit animations for its layer-backed views by default. The view’s animator proxy object reenables implicit animations automatically for you. If you want to animate layer properties directly, you can also programmatically reenable implicit animations by changing the allowsImplicitAnimation
property of the current NSAnimationContext
object to YES
. Again, you should do this only for animatable properties that are not in the preceding list.
Remember to Update View Constraints as Part of Your Animation
If you are using constraint-based layout rules to manage the position of your views, you must remove any constraints that might interfere with an animation as part of configuring that animation. Constraints affect any changes you make to the position or size of a view. They also affect the relationships between the view and its child views. If you are animating changes to any of those items, you can remove the constraints, make the change, and then apply whatever new constraints are needed.
- 动画层内容
- Core Animation--3.图层的内容动画
- CoreAnimation编程指南(三)动画层的内容
- 动画层
- 动画层
- CALayer层和动画
- 引导层动画
- 图层动画
- 层与动画
- CALayer层动画详解
- View层基础动画
- iOS 动画 图层
- div层内容居中
- 第一层内容:杂题
- 第二层内容:枚举
- 布局内容改变动画
- 动画效果 打开层/关闭层:
- 动画效果打开层 关闭层
- 机器人听觉要考虑的噪声消除
- 透彻讲解instancesRespondToSelector与respondsToSelector的区别
- linux下查看网关的命令/DNS
- #9.DHCP服务器搭建
- cuda中pinned memory(page-locked memory)
- 动画层内容
- HTML5 之工作线程
- 103.leetcode Binary Tree Zigzag Level Order Traversal(medium)[二叉树层次遍历 栈]
- Java数字证书对文件/加密/解密/签名/校验签名
- AngularJS 中的 Promise 和 设计模式
- 大数相乘 算法
- RS-485收发的零延时转换电路
- IP地址
- HDU 5729 Rigid Frameworks (求二分图连通方案数)