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.
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- back button text does not change
- iOS (objective-c) compression_decode_buffer() retu
- how to find the index position of the ARRAY Where
相关文章
- 现在使用swift开发ios应用好还是swift?
- TCC __TCCAccessRequest_block_invoke
- xcode 4 garbage collection removed?
- Unable to process app at this time due to a genera
- How can I add media attachments to my push notific
- didBeginContact:(SKPhysicsContact *)contact not in
- Custom Marker performance iOS, crash with result “
- Converting (u)int64_t to NSNumbers
After 5 hours of struggling I've just achieve it. Just change class of any NSView in .storyboard or .xib to NoClippingView and it will NOT clip any of it's subviews.
Why do I override masksToBounds in NoClippingLayer? Because some native AppKit classes change this property of all sublayers in runtime without any warnings. For example, NSCollectionView do this for views of it's cells.
The behaviour around this seems to have changed. You just need to set the view's layer to not mask to bounds.
I couldn't get any of these solutions to work. I think you may have to just change your view hierarchy so that views don't draw outside of their frame. You can create an intermediary view that doesn't do any drawing but has a larger frame to allow for a larger area.
wantsDefaultClipping method works... both the parent & the child need to override wantsDefaultClipping.
Once you go that route, however, cleaning up after yourself is cumbersome.
Here's my solution for attaching text to an NSProgressBar:
Thanks to BGHUDAppKit and stackoverflow
I was able to solve this by overriding
wantsDefaultClipping
of the subviews to returnNO
.If you are using autolayout, override
alignmentRectInsets
to expand the clipping area, making it larger than the alignment rectangle. This example gives a space of 50 on all sides: