maskToBounds和cornerRadius之间的关系是什么? [英] what is relation between masksToBounds and cornerRadius?
问题描述
我的滚动条有一些视图 cornerRadius = 10.0
和 masksToBounds = YES
。
My scroll has some views that is cornerRadius = 10.0
and masksToBounds = YES
.
这会导致滚动滚动视图时出现性能问题。虽然我尝试了每个视图的 shouldRasterize
设置为 YES
,但问题仍未解决。
This causes a performance issue for scrolling my scroll view. Though I tried each view's shouldRasterize
is set YES
, the issue is not solved.
但是,我知道这个问题的解决方案。这就是 masksToBound
设置否
。 ( masksToBound的
默认值为NO)
虽然 masksToBound
是否
,我的观点的角落仍然有曲线,性能问题也解决了。
However, I know the solution for this issue. That is what masksToBound
is set NO
. (masksToBound's
default value is NO)
Although masksToBound
is NO
, my views's corners still have curve and the performance issue is solved, too.
我想知道 cornerRadius <之间的关系/ code>和
masksToBounds
。我担心此设置会出现意外问题。
I want to know about relation between cornerRadius
and masksToBounds
. I'm afraid of unexpected issues with this setting.
谢谢。
推荐答案
提供 cornerRadius
后,指定用于绘制接收者背景圆角的半径。
After providing cornerRadius
which specifies a radius used to draw the rounded corners of the receiver’s background.
现在它依赖于 masksToBounds
,它确定子层是否被剪切到接收器的边界。因此,如果将其设置为 YES
,则会将与图层边界匹配的隐式遮罩应用于图层,包括 cornerRadius $ c的效果$ c>财产。如果设置为
YES
并指定了mask属性,则将两个掩码相乘以获得实际的掩码值。
Now it depends on masksToBounds
which determines if the sublayers are clipped to the receiver’s bounds. So if it is set to YES
, an implicit mask matching the layer bounds is applied to the layer, including the effects of the cornerRadius
property. If it is set to YES
and a mask property is specified, the two masks are multiplied to get the actual mask values.
例如:
如果您在带有图像内容的 CALayer
上设置该图像,图像仍然是在角半径边界外绘制。您可以通过将 sublayer.masksToBounds
设置为 YES
来解决此问题;但如果你这样做,阴影就不会出现,因为它们会被掩盖掉!
If you set that on a CALayer
with image contents, the image will still be drawn outside the corner radius boundary. You can solve this by setting sublayer.masksToBounds
to YES
; but if you do that, the shadows won’t show up because they’ll be masked out!
这篇关于maskToBounds和cornerRadius之间的关系是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!