addKeyframe(withRelativeStartTime:relativeDuration:animations:)
Specifies the timing and animation values for a single frame of a keyframe animation.
Declaration
class func addKeyframe(withRelativeStartTime frameStartTime: Double, relativeDuration frameDuration: Double, animations: @escaping () -> Void)Parameters
- frameStartTime:
The time at which to start the specified animations. This value must be in the range
0to1, where0represents the start of the overall animation and1represents the end of the overall animation. For example, for an animation that is two seconds in duration, specifying a start time of0.5causes the animations to begin executing one second after the start of the overall animation. - frameDuration:
The length of time over which to animate to the specified value. This value must be in the range
0to1and indicates the amount of time relative to the overall animation length. If you specify a value of0, any properties you set in theanimationsblock update immediately at the specified start time. If you specify a nonzero value, the properties animate over that amount of time. For example, for an animation that is two seconds in duration, specifying a duration of0.5results in an animation duration of one second. - animations:
A block object containing the animations you want to perform. This is where you programmatically change any animatable properties of the views in your view hierarchy. This block takes no parameters and has no return value. This parameter must not be
nil.
Discussion
To animate view properties during a keyframe animation, call this method from within the animation block you pass to the animateKeyframes(withDuration:delay:options:animations:completion:) method. To animate between different values, or to tweak the timing of your view property animations, you can call this method multiple times within a block.
The view properties you change in the animations block animate over the timespan you specify in frameDuration parameter. The properties do not begin animating until the time you specify in the frameStartTime parameter. After the frame start time, the animation executes over its specified duration or until interrupted by another animation.
See Also
Animating views
animate(_:changes:completion:)animate(springDuration:bounce:initialSpringVelocity:delay:options:animations:completion:)animate(withDuration:delay:options:animations:completion:)animate(withDuration:animations:completion:)animate(withDuration:animations:)transition(with:duration:options:animations:completion:)transition(from:to:duration:options:completion:)animateKeyframes(withDuration:delay:options:animations:completion:)perform(_:on:options:animations:completion:)animate(withDuration:delay:usingSpringWithDamping:initialSpringVelocity:options:animations:completion:)performWithoutAnimation(_:)modifyAnimations(withRepeatCount:autoreverses:animations:)