The above answers didn't work for my scenario but led me to a solution.
The updated link to @Peter's answer was helpful: scaleUnitSquareToSize
I have found two soultions for zooming:
- Cropping the bounds manually
- Scalling the bounds with
scaleUnitSquareToSize
I have created a small test project. Both solutions can be found on my GitHub repo : BoundsAndFramesCroppingAndScalling
To understand bounds vs frames read this SO article: difference-between-the-frame-and-the-bounds.
Swift scalling code:
let scaleSize = NSSize(width: 0.5, height: 0.5)
// 0.5 - Half the size
// 1.0 - No calling
// 2.0 - double the size , ... etc
myView?.scaleUnitSquare(to: scaleSize)
myView?.needsDisplay = true