What is the best approach to frame animation in NSView?

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") }) } 
+7
cocoa swift macos caanimation
source share

No one has answered this question yet.

See related questions:

562
Cocoa: What is the difference between frame and border?
184
What is the best way to move NSMutableArray?
135
Best way to change background color for NSView
3
NSAnimationContext does not update frame size for NSButton
3
How to update the position of the NSView layer and the anchor point for conversion at the same time as the NSView frame for mouse events
2
What is the best way to resize text in NSView when resizing?
one
NSView animated animation not working
one
How to force a redraw of a CALayer during an animation that changes its borders
0
NSView Frame Origin Get Reset After Animation (Animator Proxy)
0
Is it safe to use CABasicAnimation with keyPath "frameOrigin"?

All Articles