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!
Asked
Active
Viewed 395 times
0

mashers
- 1,009
- 7
- 22
2 Answers
1
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.

pointum
- 2,987
- 24
- 31
-
Perfect! Thank you! I did see the `timingFunction` property but for some reason it didn't register as what I needed. The docs for NSView animation are a mess and make it sounds much more complicated than it really is. – mashers Feb 09 '19 at 15:38
-
2To complete the snippet you provided, I had to import QuartzCore and then do `context.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];` – mashers Feb 09 '19 at 15:38
1
Swift version of pointium's answer:
NSAnimationContext.current.timingFunction = .init(name: .linear)

Tamás Sengel
- 55,884
- 29
- 169
- 223