December 2018
Intermediate to advanced
414 pages
10h 19m
English
It's often useful to listen for frame or bounds changes, in order to resize other aspects.
Listening to frame changes can be done as follows:
let view = NSView(frame: .zero)let observer = view.observe(\NSView.frame) { (view, change) in print("\(view.frame), \(change.oldValue) \(change.newValue)")}view.frame = NSRect(x: 0, y: 0, width: 100, height: 100)// Later in code, in order to stop the observationobserver.invalidate()
The preceding code snippet will print the following:
(0.0, 0.0, 100.0, 100.0), nil nil
As you will note, both oldValue and newValue are nil. It is possible to use a different API if you are interested in the changes.
This is especially powerful when needing to recompute some available ...
Read now
Unlock full access