masksToBounds与clipsToBounds [英] masksToBounds vs. clipsToBounds

查看:108
本文介绍了masksToBounds与clipsToBounds的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从我的角度来看,UIView clipsToBounds 和CALayer masksToBounds 做同样的工作.

我找不到它们之间的任何区别.

有人可以请他们解释他们之间的不同吗?

解决方案

masksToBounds

该层的任何超出其边界的子层都将被裁剪到这些边界.在这种情况下,可将层视为通向其子层的窗口;窗口边缘以外的任何内容都将不可见.当masksToBounds为NO时,不会发生剪裁.

当此属性的值为true时,Core Animation将创建一个隐含的剪贴蒙版,该蒙版与图层的边界匹配并包括任何角半径效果.如果还指定了mask属性的值,则将两个掩码相乘以获得最终的掩码值.

您可以在 API参考中获得更多信息.>

clipToBounds

对于部分位于主视图之外的子视图,clipsToBounds的用例更多.例如,我在其父级(矩形)UIView的边缘上有一个(圆形)子视图.如果将clipsToBounds设置为YES,则仅显示一半的圆/子视图.如果设置为否",则会显示整个圆圈.刚遇到这个,所以想分享

有关更多信息,示例链接

From my point of view both UIView clipsToBounds and CALayer masksToBounds do the same job.

I couldn't find any difference between them.

Can somebody kindly explain how they are different?

解决方案

masksToBounds

Any sublayers of the layer that extend outside its boundaries will be clipped to those boundaries. Think of the layer, in that case, as a window onto its sublayers; anything outside the edges of the window will not be visible. When masksToBounds is NO, no clipping occurs.

When the value of this property is true, Core Animation creates an implicit clipping mask that matches the bounds of the layer and includes any corner radius effects. If a value for the mask property is also specified, the two masks are multiplied to get the final mask value.

you can get the more information in API Reference.

clipToBounds

The use case for clipsToBounds is more for subviews which are partially outside the main view. For example, I have a (circular) subview on the edge of its parent (rectangular) UIView. If you set clipsToBounds to YES, only half the circle/subview will be shown. If set to NO, the whole circle will show up. Just encountered this so wanted to share

for more information sample link

这篇关于masksToBounds与clipsToBounds的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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