iphone - 动画的表现非常差,当视图的影子是 [英] iphone - Animation's performance is very poor when view's shadow is on

查看:177
本文介绍了iphone - 动画的表现非常差,当视图的影子是的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个的UILabel 的CALayer 阴影on.And我只是将它通过左右的UIView 动画。

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.

我觉得是的阴影的UILabel ,因为如果我把影子关闭,动画变得像正常一样光滑这会导致动画问题。

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.

我已经尝试使用 view.layer.shouldRasterize = YES;

但还是动画的表现是存在的。

But still the animation performance is there.

任何人都可以给我一些提示?

Anyone can give me some hints?

感谢

推荐答案

您可以大大利用提高的CALayer的影子表现的 shadowPath 属性 - 这是允许绘制阴影,而无需重新计算层的alpha遮罩。对于矩形视图,您会使用这样的:

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:

theView.layer.shadowPath = [UIBezierPath bezierPathWithRect:theView.bounds].CGPath;

或者,如果它的边角圆润,

or, if its corners are rounded,

theView.layer.shadowPath = [UIBezierPath bezierPathWithRoundedRect:theView.bounds cornerRadius:theView.layer.cornerRadius].CGPath;

请注意,这是视图四周的阴影边界,如果你想上的文字本身的影子更好的性能,您可能需要使用标签的文字阴影属性(牺牲的CALayer阴影的细微,如模糊,为更好的渲染速度),或者 - 一个更复杂的选项创建一个CGPathRef作为要使用的图层的 shadowPath 从文本字形自己。

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.

这篇关于iphone - 动画的表现非常差,当视图的影子是的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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