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 - 阴影会导致性能下降?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:CALayer - 阴影会导致性能下降?
基础教程推荐
- UIImage 在开始时不适合 UIScrollView 2022-01-01
- 如何比较两个 NSDate:哪个是最近的? 2022-01-01
- Xcode UIView.init(frame:) 只能在主线程中使用 2022-01-01
- iOS - UINavigationController 添加多个正确的项目? 2022-01-01
- Play 商店的设备兼容性问题 2022-01-01
- navigationItem.backBarButtonItem 不工作?为什么上一个菜单仍然显示为按钮? 2022-01-01
- 如何将图像从一项活动发送到另一项活动? 2022-01-01
- 为什么姜饼模拟器方向卡在应用程序中? 2022-01-01
- Android Volley - 如何动画图像加载? 2022-01-01
- SwiftUI-ScrollViewReader的ScrollTo不滚动 2022-01-01
