How to set animation curve when using UIView's keyframe animation :
animateKeyframesWithDuration:delay:options:animations:completion:
Whatever I do in the animation block seems to be linear (unless I use the UIViewKeyframeAnimationOptionCalculationModeCubic option but this isn't what I want).
I'd like to have an ease out curve on the animation like the UIViewAnimationOptionCurveEaseOut option when using regular animation :
animateWithDuration:delay:options:animations:completion:
Start by tapping on a clip or effect in your project, which will change options in the bottom toolbar. Above the toolbars on the right, you'll see a diamond icon with a plus sign above it — that's the keyframe tool. Tap on the keyframe tool to add a keyframe marker to your clip.
To create an action in a digital animation sequence, you first need to define the start and end points for that action. These markers are called keyframes and they're used as anchor points for actions in all different types of animation programmes, including Adobe After Effects, Animate and Character Animator.
Swift 2.0 will not allow casting of UIViewAnimationOptions as UIViewKeyframeAnimationOptions. It will also not allow |ing them together.
However, there is an initializer for UIViewKeyframeAnimationOptions that takes a rawValue. So, the following code works to put UIViewAnimationOptions into UIViewKeyframeAnimationOptions:
let animationOptions: UIViewAnimationOptions = .CurveEaseOut
let keyframeAnimationOptions: UIViewKeyframeAnimationOptions = UIViewKeyframeAnimationOptions(rawValue: animationOptions.rawValue)
Then I can pass keyframeAnimationOptions to animateKeyframesWithDuration and everything works great.
For Swift 4:
let animationOptions = AnimationOptions.curveEaseOut
let options = KeyframeAnimationOptions(rawValue: animationOptions.rawValue)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With