CALayer - Shadow causes a performance hit?(CALayer - 阴影会导致性能下降?)
问题描述
所以我在我的导航控制器上做一些自定义动画以及它推动和弹出视图控制器的方式.
So I am doing some custom animations on my navigationcontroller and the way it pushes and pops the viewControllers.
一切顺利.一旦我添加以下代码(在 UINavigationController
的子类中),我就会面临巨大的性能损失.添加阴影后,所有动画都变得非常滞后.这是预期的还是我在代码中做错了什么?
Everything runs smooth. As soon as I add the following code (In a subclass of UINavigationController
), I face a huge performance hit. After adding a shadow all animations become very laggy. Is this expected or am I doing something wrong in the code?
// This code gets called once during NavigationController initialization.
[self.view setClipsToBounds:NO];
[self.view.layer setCornerRadius:5];
[self.view.layer setShadowOffset:CGSizeMake(0, 20)];
[self.view.layer setShadowColor:[[UIColor yellowColor] CGColor]];
[self.view.layer setShadowRadius:20.0];
[self.view.layer setShadowOpacity:1];
将我的阴影半径更改为 1,它仍然很慢
Changed my shadow radius to 1 and it's still slow
推荐答案
添加阴影应该会导致减速.shadowRadius
为 20 非常高,会特别慢.
You should expect a slowdown from adding a shadow. A shadowRadius
of 20 is very high and will be especially slow.
提高阴影渲染速度的另一个关键:设置 shadowPath
属性.它可以提供很大帮助.
The other key to improve shadow rendering speed: set the shadowPath
property. It can help dramatically.
这篇关于CALayer - 阴影会导致性能下降?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!