【发布时间】:2015-03-21 17:25:05
【问题描述】:
我目前正在阅读 Apple 的 Core Animation Guide,在那里我发现了以下关于 iOS 中支持层的视图的文章:
如果您想使用 Core Animation 类来启动动画,您必须从基于视图的动画块内发出所有 Core Animation 调用。 UIView 类默认禁用图层动画,但在动画块内重新启用它们。因此,您在动画块之外所做的任何更改都不是动画。
就在引用下方,文档包括以下代码清单:
[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"];
}];
这意味着CALayers 上支持UIViews 的隐式和显式动画都必须放在动画块中。
但是,我发现这显然是不真实的。具体来说,我已经使用UIView 动画块之外的核心动画类成功地实现了显式动画。
我是否误解了这段话,或者它已经过时了,还是其他什么?
一些补充说明:
我假设“UIView 类默认禁用图层动画但在动画块内重新启用它们”指的是+[UIView setAnimationsEnabled:] 方法。当我回到可以这样做的计算机时,我会检查+[UIView areAnimationsEnabled] 是否返回YES 或NO。
【问题讨论】:
标签: ios uiview core-animation calayer