我有一个NSView我需要注意如果帧改变。如何观察NSView框架更改?
class CustomView: NSView {
override var frame: NSRect {
didSet {
Swift.print("changed frame: \(self.frame)")
}
}
}
但是,如果superView框架的大小已调整,我只能得到这个“notifikation”。
如果我做这样的事情的NSView类中:
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)
}
的didSet
功能doesn't反应都没有。尽管帧大小已更改。感谢您的任何建议。
的可能的复制[有一个UIView调整事件?(https://stackoverflow.com/questions/4000664/is-there-a-uiview-resize-event) – GIJOW
尝试'bounds' .. – sCha
@sCha与'bounds'相同 –