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.
The behaviour around this seems to have changed. You just need to set the view's layer to not mask to bounds.
view.wantsLayer = true
view.layer?.masksToBounds = false
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.
class NoClippingLayer: CALayer {
override var masksToBounds: Bool {
set {
}
get {
return false
}
}
}
class NoClippingView: NSView {
override var wantsDefaultClipping: Bool {
return false
}
override func awakeFromNib() {
super.awakeFromNib()
wantsLayer = true
layer = NoClippingLayer()
}
}
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.
I was able to solve this by overriding wantsDefaultClipping
of the subviews to return NO
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With