A class that animates changes to views and allows the dynamic modification of those animations.


A UIViewPropertyAnimator object lets you animate changes to views and dynamically modify your animations before they finish. With a property animator, you can run your animations from start to finish normally or you can turn them into interactive animations and control the timing yourself. The animator operates on animatable properties of views, such as the frame, center, alpha, and transform properties, creating the needed animations from the blocks you provide.

When creating a property animator object, you specify the following:

  • A block containing code that modifies the properties of one or more views.

  • The timing curve that defines the speed of the animation over the course of its run.

  • The duration (in seconds) of the animation.

  • An optional completion block to execute when the animations finish.

In your animation blocks, set the value of an animatable property to the final value you want reflected by that view. For example, if you want to fade out a view, you would set its alpha property to 0 in your block. The property animator object creates an animation that adjusts the value of that property from its initial value to the new value that you specified in your block.

The speed at which the value of a property changes is controlled by the timing curve you specify when creating the property animator. Property animators include support for the built-in UIKit animation curves such as linear, ease-in, and ease-out. You can also use a cubic Bezier curve or a spring function to control the timing of the animations.

If you create your animator using one of the standard initialization methods, you must explicitly start your animations by calling the startAnimation() method. If you want to start the animations immediately after the creation of your animator, use the runningPropertyAnimator(withDuration:delay:options:animations:completion:) method instead of the standard initializers.

This class adopts the UIViewAnimating and UIViewImplicitlyAnimating protocols, which define the methods for starting, stopping, and modifying your animations. For more information about the methods of those protocols, see UIViewAnimating and UIViewImplicitlyAnimating.

Modifying Animations Dynamically

A property animator gives you programmatic control over the timing and execution of the animations. Specifically, you can:

Most of the basic behavior is controlled by the properties of the UIViewAnimating protocol, which this class adopts. Use those methods and properties to start, pause, resume, and stop the animations. You can also use them to scrub through the animation and change its direction. Use the methods and properties of this class to modify the animation blocks themselves and to update the timing information.


Initializing a Property Animator

Modifying Animations

func addAnimations(() -> Void)

Adds the specified animation block to the animator.

func addAnimations(() -> Void, delayFactor: CGFloat)

Adds the specified animation block with a delay.

func addCompletion((UIViewAnimatingPosition) -> Void)

Adds the specified completion block to the animator.

Accessing the Animation Parameters

var duration: TimeInterval

The total duration (in seconds) of the main animations.

var delay: TimeInterval

The delay (in seconds) after which the animations begin.

var timingParameters: UITimingCurveProvider?

The information used to determine the timing curve for the animation.

var isInterruptible: Bool

A Boolean value indicating whether the animator is interruptible and can be paused or stopped.

var isUserInteractionEnabled: Bool

A Boolean value indicating whether views receive touch events while animations are running.

var isManualHitTestingEnabled: Bool

A Boolean value indicating whether your app manages hit-testing while animations are in progress.

var scrubsLinearly: Bool

A Boolean value indicating whether a paused animation scrubs linearly or uses its specified timing information.


Instance Properties

See Also

First Steps

protocol UIViewAnimating

An interface for implementing custom animator objects.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software