动画停止后一一删除CALayers
当用户单击“飞入”时,我想制作一堆硬币 - >硬币会沿着弯曲的路径飞行并排列成一堆。我使用了 CALayer:
CALayers *coinLayer = [CALayers layer];
coinLayer.backgroundColor = [UIColor clearColor].CGColor;
coinLayer.contents = (id)[UIImage imageNamed:@"head coin.png"].CGImage;
coinLayer.frame = CGRectMake(100, 500 - (10*coin), 55, 21);
coin = coin + 1;
[self.view.layer addSublayer:coinLayer];
我已经在弯曲路径中完成了动画,但是如果我以这种方式添加我的 coinLayer,那么如果我不将其添加到数组中,我如何删除 CALayer。
例如,我有一堆数字,我在堆栈中添加1,2,3,4,5,6,7,8,9。当删除4个数字时,它会一一从9减到8...减到6。在我的代码中,当我在视图层中添加 CALayer 时,这是正确的吗?如何像示例一样一层一层地删除层?
太感谢了!
I want to make a stack of coin, when user click "Fly in" -> coin'll fly in a curved path and arrange in a stack. I used CALayer:
CALayers *coinLayer = [CALayers layer];
coinLayer.backgroundColor = [UIColor clearColor].CGColor;
coinLayer.contents = (id)[UIImage imageNamed:@"head coin.png"].CGImage;
coinLayer.frame = CGRectMake(100, 500 - (10*coin), 55, 21);
coin = coin + 1;
[self.view.layer addSublayer:coinLayer];
I've done with animation in curved path but if i add my coinLayer in this way, then how can i remove CALayer if i don't add it in an array.
For example, i have a stack of number, i add 1,2,3,4,5,6,7,8,9 in the stack. When remove 4 numbers, it will do from 9 down to 8... down to 6 one by one. In my code, is that correct when i add CALayer in view's layer? How can i remove layers one by one as same as example?
Thank you so much!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
与其创建和删除 CALayer 对象,不如将它们存储在数组中,并在需要时简单地设置它们的隐藏属性。
在标题中:
在 m 文件中:
当动画完成时,只需将硬币的隐藏属性设置为 true 即可。
我使用此方法一次处理数千个 CALayer 对象,它比不断创建新的 CALayer 更加资源友好。
Rather than creating and deleting CALayer objects it's better to store them in an array and simply set their hidden property whenever you need them.
in the header:
In the m file:
When the animation finishes simply set the coin's hidden property to be true.
I use this method to handle thousands of CALayer objects at once and it's much more resource friendly than constantly creating new CALayers.