Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to set animation curve when using keyframe animation in ios?

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:
like image 874
Alexis Avatar asked Dec 17 '13 16:12

Alexis


People also ask

How do you use keyframe on Iphone?

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.

How is keyframe used in animation?

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.


1 Answers

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)
like image 139
eskimwier Avatar answered Sep 20 '22 15:09

eskimwier