开发者

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'开发者_StackOverflow中文版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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜