Ideally I'd need something like UIView.animateWithDuration
, however I know that this is not an API that's available on macOS. What's the best way to manipulate the actual frame of an NSView and animate the changes?
I tried going for CABasicAnimation
, however that's performed on a CALayer rather than the view itself.
What I need is to animate the actual view frame... (or maybe that's a bad practice and there's an alternative?)
So for that reason, after a bit of digging I found NSAnimationContext
. That however seems to simply interpolate / fade between two states which is not the feel I am going for.
Here's a small sample of the code I have:
override func mouseDown(with event: NSEvent) {
let newSize = NSMakeRect(self.frame.origin.x,
self.frame.origin.y - 100,
self.frame.width, self.frame.height + 100)
NSAnimationContext.runAnimationGroup({ (context) -> Void in
context.duration = 0.5
self.animator().frame = newSize
}, completionHandler: {
Swift.print("completed")
})
}