ios中的animationDidStop(animationDidStop in ios)

编程入门 行业动态 更新时间:2024-10-24 04:36:07
ios中的animationDidStop(animationDidStop in ios)

当用户点击屏幕时,我正在生成CALayer 。 然后我使用Animation将该图层转换为特定位置。 然后我在animationDidStop使用此代码删除它:

[mylayer removeFromSuperLayer];

这里一切正常,但是当我在前一个动画停止之前再次点击时,我的当前图层不会从超级图层中删除。 在这种情况下如何删除它?

I'm generating CALayer when user taps the screen. Then I'm translating that layer to certain position using Animation. Then I'm removing it using this code in animationDidStop:

[mylayer removeFromSuperLayer];

Here everything is working fine, but when I tap again before the previous animation stops, my current layer is not removed from the superlayer. How do I removed it under these circumstances?

最满意答案

如果每次都创建一个新图层,那么委托方法只能删除当前的图层(即较旧的图层将丢失)

您可以尝试在动画周围使用CATransaction begin/commit对并添加完成块,这样您就可以为每个动画传递图层参考

[CATransaction begin]; [CATransaction setCompletionBlock:^{ [myLayer removeFromSuperlayer]; }]; //your existing animation code [CATransaction commit];

If you are creating a new layer each time, then the delegate method will only be able to remove the current one (i.e. the older one will be lost)

You could try using CATransaction begin/commit pairs around your animations and adding completion block, this way you can pass the layers reference for each animation

[CATransaction begin]; [CATransaction setCompletionBlock:^{ [myLayer removeFromSuperlayer]; }]; //your existing animation code [CATransaction commit];

更多推荐

本文发布于:2023-08-03 19:36:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1396269.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:ios   animationDidStop

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!