what is relation between masksToBounds and cornerRadius?

北慕城南 提交于 2019-12-17 18:33:22

问题


My scroll has some views that is cornerRadius = 10.0 and masksToBounds = 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.

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.

I want to know about relation between cornerRadius and masksToBounds. I'm afraid of unexpected issues with this setting.

Thank you.


回答1:


After providing cornerRadius which specifies a radius used to draw the rounded corners of the receiver’s background.

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.

For example:

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!




回答2:


There is not any specific relation ship .. actually when you call the Corner Radius it will crop the view at what radius you have passed and MaskToBound:Yes make it transparent to that part which you have cropped else it would be visible...



来源:https://stackoverflow.com/questions/11324878/what-is-relation-between-maskstobounds-and-cornerradius

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!