[英]CALayer explicit animation
Guys I'm trying to perform a CABasicAnimation (just for the test purposes) following the Apple's guide 伙计们,我正在尝试按照Apple指南执行CABasicAnimation(仅出于测试目的)
There's a piece of code: 有一段代码:
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;
Which tells that I should actually change a property at the end. 这表明我实际上应该在最后更改属性。 But it seems not working fine(it changes opacity immediately) - the duration is not 5 (I changed it to 5 for better visibility) so the animation is not CABasicAnimation but implicit.
但是它似乎不能正常工作(它会立即更改不透明度)-持续时间不是5(为了更好的可见性,我将其更改为5),所以动画不是CABasicAnimation而是隐式的。 It only works when I set
theLayer.opacity = 0.0;
仅当我设置
theLayer.opacity = 0.0;
时才有效theLayer.opacity = 0.0;
BEFORE I add the animation to layer
. 在将动画添加到
layer
。 Am I doing something wrong or it is a bug in docs? 我是在做错什么还是文档中的错误? PS running the latest XCode, iOS 7.1 simulator.
PS运行最新的XCode,iOS 7.1模拟器。
Update the model layer before adding the animation. 添加动画之前,请更新模型层。
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"];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.