macosnsanimationcontextnsanimation

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!


Solution

  • 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.