CALayer - 暗影导致性能下降? [英] CALayer - Shadow causes a performance hit?

查看:94
本文介绍了CALayer - 暗影导致性能下降?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我在我的navigationcontroller上做了一些自定义动画,以及它推动和弹出viewControllers的方式。

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

推荐答案

您应该期望通过添加阴影来减速。 20的 shadowRadius 非常高,速度特别慢。

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 - 暗影导致性能下降?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆