1

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?

4

1 回答 1

0

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

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

[CATransaction begin];

[CATransaction setCompletionBlock:^{
    [myLayer removeFromSuperlayer];
}];

//your existing animation code

[CATransaction commit];
于 2012-12-15T12:04:24.080 回答