Class

UIViewPropertyAnimator

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

Declaration

@interface UIViewPropertyAnimator : NSObject

Overview

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 runningPropertyAnimatorWithDuration: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.

Topics

Initializing a Property Animator

initWithDuration:curve:animations:

Initializes the animator with a built-in UIKit timing curve.

initWithDuration:controlPoint1:controlPoint2:animations:

Initializes the animator object with a cubic Bézier timing curve.

initWithDuration:dampingRatio:animations:

Initializes the animator object with spring-based timing information.

initWithDuration:timingParameters:

Initializes the animator object with a custom timing curve object.

runningPropertyAnimatorWithDuration:delay:options:animations:completion:

Creates and returns an animator object that begins running its animations immediately.

Modifying Animations

addAnimations:

Adds the specified animation block to the animator.

addAnimations:delayFactor:

Adds the specified animation block with a delay.

addCompletion:

Adds the specified completion block to the animator.

continueAnimationWithTimingParameters:durationFactor:

Adjusts the timing and duration of a paused animation.

Accessing the Animation Parameters

duration

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

delay

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

timingParameters

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

interruptible

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

userInteractionEnabled

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

manualHitTestingEnabled

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

scrubsLinearly

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

pausesOnCompletion

A Boolean value that indicates whether a completed animation remains in the active state.

Relationships

Inherits From

See Also

First Steps

UIViewAnimating

An interface for implementing custom animator objects.