伙计们,我正在尝试在 Apple's guide 之后执行 CABasicAnimation(仅用于测试目的)
有一段代码:
CABasicAnimation* fadeAnim = [CABasicAnimation animationWithKeyPath:@"opacity"];
fadeAnim.fromValue = [NSNumber numberWithFloat:1.0];
fadeAnim.toValue = [NSNumber numberWithFloat:0.0];
fadeAnim.duration = 5.0;
[theLayer addAnimation:fadeAnim forKey:@"opacity"];
// Change the actual data value in the layer to the final value.
theLayer.opacity = 0.0;
这表明我实际上应该在最后更改一个属性。但它似乎工作不正常(它立即改变不透明度) - 持续时间不是 5(我将其更改为 5 以获得更好的可见性)所以动画不是 CABasicAnimation 而是隐式的。
它仅在我将动画添加到 layer
之前设置 theLayer.opacity = 0.0;
时有效。我做错了什么还是文档中的错误?
P.S 运行最新的 XCode,iOS 7.1 模拟器。
最佳答案
在添加动画之前更新模型层。
CABasicAnimation* fadeAnim = [CABasicAnimation animationWithKeyPath:@"opacity"];
fadeAnim.fromValue = [NSNumber numberWithFloat:1.0];
fadeAnim.toValue = [NSNumber numberWithFloat:0.0];
fadeAnim.duration = 5.0;
// Change the actual data value in the layer to the final value.
theLayer.opacity = 0.0;
[theLayer addAnimation:fadeAnim forKey:@"opacity"];
关于ios - CALayer显式动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23368846/