mashers
mashers

Reputation: 1099

How do I animate NSView with curve

I know how to animate NSView objects using +[NSAnimationContext runAnimationGroup:completionHandler:], but I can't see a way of setting the animation curve on this type of animation. I see that NSAnimation has an init method which includes a NSAnimationCurve parameter, but I cannot figure out how to specify what should actually happen during the animation using this method. The documentation for NSAnimation is really difficult to understand and I can't find any examples. So if somebody could explain how I can either add a curve to NSAnimationContext animations or specify the animations in a NSAnimation animation, that would be really helpful. Thanks in advance!

Upvotes: 1

Views: 538

Answers (2)

glyvox
glyvox

Reputation: 58149

Swift version of pointium's answer:

NSAnimationContext.current.timingFunction = .init(name: .linear)

Upvotes: 1

pointum
pointum

Reputation: 3177

What you’re looking for is timingFunction.

You can set it inside of the runAnimationGroup block:

NSAnimationContext.currentContext.timingFunction = …

and either use predefined functions or create your own with control points.

Upvotes: 2

Related Questions