Make NSView NOT clip subviews outside of its bounds
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:
override var alignmentRectInsets: NSEdgeInsets {
return NSEdgeInsets(top: 50.0, left: 50.0, bottom: 50.0, right: 50.0)
}
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
.