Make NSView NOT clip subviews outside of its bound

2019-01-22 13:14发布

Is it possible to make an NSView not clip its subviews that are outside of the bounds? On iOS I would simply set clipsToBounds of my UIView no NO. But NSView doesn't have such a property. I tried experimenting with wantsLayer, masksToBounds, wantsDefaultClipping, but all of these seem to only change the clipping of the drawRect method, not the subviews.

7条回答
一纸荒年 Trace。
2楼-- · 2019-01-22 14:20

For people looking for equivalent swift code:
Add this code to a subClass of NSView:

override var wantsDefaultClipping:Bool{return false}//avoids clipping the view

You don't have to change the parent. as long as the parent has a big enough clipping area. But its convenient to also add this variable to the parent.

Update 1:

This isnt an easy subject, ive spent weeks researching this and my best solution can be found here: http://stylekit.org/blog/2015/12/24/The-odd-case-of-luck/

Update 2:

To see the above concept in action check this article: http://stylekit.org/blog/2015/12/30/Graphic-framework-for-OSX/

查看更多
登录 后发表回答