Ideally, I need something like UIView.animateWithDuration , however, I know that this is not an API available on macOS. How can I control the actual NSView frame and animate the changes?
I tried switching to CABasicAnimation , however this was done on CALayer and not on the view itself.
I need to animate the actual angle ... (or maybe this is bad practice and is there an alternative?)
Therefore, for this reason, after a little digging, I found NSAnimationContext . This, however, seems to simply interpolate / disappear between the two states, which is not the feeling I'm going for.
Here is a small example 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") }) }
cocoa swift macos caanimation
Martin Velchevski
source share