I have a NSView from which I need to be noticed if the frame changed.
class CustomView: NSView {
override var frame: NSRect {
didSet {
Swift.print("changed frame: \(self.frame)")
}
}
}
But I only get this "notifikation" if the superView frame is resized.
If I do something like this inside the NSView class:
NotificationCenter.default.addObserver(forName: Notification.Name(rawValue: "changeOwnSize"), object: nil, queue: nil) { notification in
let newSize = NSSize(width: self.frame.width / 2, height: self.frame.height)
self.setFrameSize(newSize)
}
The didSet
function doesn´t react at all. Although the frame size is changed. Thanks for any advice.