繁体   English   中英

CALayer显式动画

[英]CALayer explicit animation

伙计们,我正在尝试按照Apple指南执行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而是隐式的。 仅当我设置theLayer.opacity = 0.0;时才有效theLayer.opacity = 0.0; 在将动画添加到layer 我是在做错什么还是文档中的错误? PS运行最新的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"];

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM