iphone - 当视图的阴影打开时,动画的性能非常差
我有一个 UILabel
,上面有 CALayer
阴影。我只是通过 UIView
动画移动它。
性能很差,我可以看到动画一点也不流畅。
我认为是 UILabel
的阴影导致了动画问题,因为如果我关闭阴影,动画就会变得像正常一样平滑。
我尝试过使用 view.layer.shouldRasterize = YES;
但动画性能仍然存在。
任何人都可以给我一些提示吗?
谢谢
I have a UILabel
with CALayer
shadow on.And I just move it around via UIView
animation.
The performance is poor and I can see the animation is not smooth at all.
I think it is the shadow of the UILabel
which causes the animation problem because if I turn the shadow off, the animation becomes as smooth as normal.
I have tried using view.layer.shouldRasterize = YES;
But still the animation performance is there.
Anyone can give me some hints?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以通过使用 CALayer 的
shadowPath
属性来极大地提高 CALayer 阴影的性能,这允许它绘制阴影而无需重新计算图层的 alpha 遮罩。对于矩形视图,您可以像这样使用它:或者,如果它的角是圆角的,
请注意,这是视图边框周围的阴影 - 如果您希望文本本身的阴影有更好的性能,您需要使用标签的文本阴影属性(牺牲了 CALayer 阴影的优点,例如模糊,以获得更好的渲染速度)或者 - 一个更复杂的选项 - 创建一个 CGPathRef 以用作来自文本的图层的
shadowPath
字形本身。You can greatly improve the performance of a CALayer’s shadow by using its
shadowPath
property—this allows it to draw the shadow without having to recalculate the alpha mask of the layer. For a rectangular view, you’d use it like this:or, if its corners are rounded,
Note that this is a shadow around the view’s borders—if you want better performance on the shadow on the text itself, you either need to use the label’s text-shadow properties (which sacrifice the niceties of CALayer shadows, like blur, for better rendering speed) or—a much more complicated option—create a CGPathRef to use as the layer’s
shadowPath
from the text glyphs themselves.不确定这是否是您正在寻找的答案,但我发现了这个: Drop UITextField 文本上的阴影
这可能会带来更好的性能,我还没有尝试过,但看起来会是这样。
Not sure if this is the answer you're looking for but I found this: Drop Shadow on UITextField text
It may be better performance, I haven't tried it but it seems it would be.