CALayer/CABasicAnimation opacity animation cache?

I've got a View that appears as a dialog and I am animating its opacity when I want it to be removed from the parent view.

I'm using the following code to change its opacity via a CABasicAnimation:

CALayer *opacityOutLayer = sheetView.layer;
CABasicAnimation *fadeOutAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"];
fadeOutAnimation.fromValue = [NSNumber numberWithFloat:1.0];
fadeOutAnimation.toValue = [NSNumber numberWithFloat:0.0];
fadeOutAnimation.duration = 0.255;
[opacityOutLayer addAnimation:fadeOutAnimation forKey:@"opacity"];

This looks perfect in the simulator, but not very smooth on a device. Is there any way to cache the animation (like using UIView transition cache:YES)?

I'm sure this is pretty simple but after searching the documentation and CALayer class info I can't find anything to cache it.


You could try setting layer.shouldRasterize = YES; and see if that improves performance.

But note that shouldRasterize will slow down compositing considerably as soon as the contents of your layer change. So you should only enable it for a certain animation and then disable it again.

链接地址: http://www.djcxy.com/p/74180.html

上一篇: 有没有办法在iOS中检测正在运行的动画?

下一篇: CALayer / CABasicAnimation不透明度动画缓存?