cocoa – 我可以在将CAAnimation实例添加到图层后通过修改它来重用它吗?

cocoa – 我可以在将CAAnimation实例添加到图层后通过修改它来重用它吗?,第1张

概述这很有趣……我认为通过这样做 CABasicAnimation* a = [CABasicAnimation animationWithKeyPath:@"opacity"]; a.fromValue = [NSNumber numberWithFloat:0.]; a.toValue = [NSNumber numberWithFloat:1.]; a.duration 这很有趣……我认为通过这样做

CABasicAnimation* a = [CABasicAnimation animationWithKeyPath:@"opacity"];    a.fromValue = [NSNumber numberWithfloat:0.];    a.tovalue = [NSNumber numberWithfloat:1.];    a.duration = .4;    a.fillMode = kCAFillModeBoth;    a.removedOnCompletion = NO;CGfloat timeOffset = 0;for(CALayer* layer in layers){    a.beginTime = [someCommonSuperVIEw.layer convertTime:CACurrentMediaTime()fromLayer:nil] + timeOffset;    [layer addAnimation:a forKey:nil];    timeOffset += .4;}

我实际上总是修改相同的CABasicAnimation的beginTime并且只是增加它的引用计数.所以我不会让一系列图层一个接一个地消失,而是应该搞乱所有图层的开始时间,可能导致所有这些图层在最后一个时刻出现.但上面的代码实际上似乎有效,因为这些层依次淡入淡出.

那么以这种方式重用动画是否有意义?为了不在每次传递中创建它的新实例

addAnimation实际上是制作动画的深层副本而不是增加引用计数吗?

解决方法 根据 the docs:

- (voID)addAnimation:(CAAnimation *)anim forKey:(Nsstring *)key

Add an animation object to the receiver’s render tree for the specifIEd key.

Parameter anim:

The animation to be added to the render tree. Note that the object is
copIEd by the render tree,not referenced. Any subsequent
modifications to the object will not be propagated into the render
tree.

所以我认为重用相同的CAAnimation对象是安全的.

总结

以上是内存溢出为你收集整理的cocoa – 我可以在将CAAnimation实例添加到图层后通过修改它来重用它吗?全部内容,希望文章能够帮你解决cocoa – 我可以在将CAAnimation实例添加到图层后通过修改它来重用它吗?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1003583.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-22
下一篇 2022-05-22

发表评论

登录后才能评论

评论列表(0条)

保存