<分区>
从我的角度来看,UIView clipsToBounds
和 CALayer
masksToBounds
做同样的工作。
我找不到它们之间的任何区别。
谁能解释一下它们有何不同?
<分区>
从我的角度来看,UIView clipsToBounds
和 CALayer
masksToBounds
做同样的工作。
我找不到它们之间的任何区别。
谁能解释一下它们有何不同?
最佳答案
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.
您可以在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
更多信息sample link
关于ios - masksToBounds 与 clipsToBounds,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39466001/
相关文章:
ios - NSCoding 和 NSData 是什么关系?
ios - 从 UITabBarController 场景中删除标签栏项目
objective-c - Xcode 在 NSAttributedString 上调用 RTFFromRange 时生成警告,documentAttributes 为 nil
ios - AVAssetExportSession exportAsynchronouslyWithCompletionHandler 有时不起作用
swift - 如何以编程方式设置 UIPageViewController 的 subview 的约束?
ios - 未调用 alertViewShouldEnableFirstOtherButton 委托(delegate)方法