ios Maskstobounds 与 Clipstobounds
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39466001/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Maskstobounds vs clipstobounds
提问by sathishkumar_kingmaker
In my point of both clipstoboundsand maskstoboundsdoes the same job.
在我看来,clipstobounds和masktobounds都做同样的工作。
I couldn't find any difference between them.
我找不到它们之间的任何区别。
Somebody kindly explain how both are different.
有人好心解释两者有何不同。
回答by Anbu.Karthik
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.
图层的任何延伸到其边界之外的子图层都将被裁剪到这些边界。在这种情况下,将图层视为其子图层的窗口;窗口边缘之外的任何东西都将不可见。当masksToBounds 为NO 时,不会发生裁剪。
当此属性的值为 true 时,Core Animation 会创建一个与图层边界匹配并包括任何圆角半径效果的隐式剪贴蒙版。如果还指定了掩码属性的值,则将两个掩码相乘以获得最终掩码值。
you can get the more information in API Reference.
您可以在API 参考中获得更多信息。
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
clipsToBounds 的用例更多用于部分位于主视图之外的子视图。例如,我在其父(矩形)UIView 的边缘有一个(圆形)子视图。如果将 clipsToBounds 设置为 YES,则只会显示圆/子视图的一半。如果设置为 NO,将显示整个圆圈。刚遇到这个所以想分享
for more information sample link
有关更多信息示例链接
回答by Bhagabata
Clipstobounds: with?clipsToBounds?set to?YES, I'll only see the part of the subview that fits within the bounds of the superview. Otherwise, if?clipsToBounds?is set to?NO, I'll see the entire subview, even the parts outside the superview?
Clipstobounds: with?clipsToBounds?set to?YES,我只会看到子视图中适合父视图边界的部分。否则,如果?clipsToBounds? 设置为?NO,我将看到整个子视图,甚至是超级视图之外的部分?
Maskstobounds: If the?masksToBounds?property is set to YES, 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, and any sublayers that extend outside the layer's boundaries will be visible in their entirety (as long as they don't go outside the edges of any superlayer that does have masking enabled).
Maskstobounds:如果?masksToBounds? 属性设置为YES,则图层的任何延伸到其边界之外的子图层都将被裁剪到这些边界。在这种情况下,将图层视为其子图层的窗口;窗口边缘之外的任何东西都将不可见。当?masksToBounds? 为NO 时,不会发生剪裁,并且任何延伸到图层边界之外的子图层都将整体可见(只要它们不超出任何启用了遮罩的超级图层的边缘)。