当用户点击屏幕时,我正在生成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];更多推荐
发布评论