A class that animates changes to views and allows the dynamic modification of those animations.
- iOS 10.0+
- Mac Catalyst 13.0+
- tvOS 10.0+
UIView 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
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
start method. If you want to start the animations immediately after the creation of your animator, use the
running method instead of the standard initializers.
This class adopts the
UIView protocols, which define the methods for starting, stopping, and modifying your animations. For more information about the methods of those protocols, see
Modifying Animations Dynamically
A property animator gives you programmatic control over the timing and execution of the animations. Specifically, you can:
Start, pause, resume, and stop animations; see the methods of the
Scrub through a paused animation by modifying the
Change the animation’s direction using the
Modify the timing and duration of a partially complete animation by pausing the animation and using the
continuemethod to finish it.
Animation With Timing Parameters: duration Factor:
Most of the basic behavior is controlled by the properties of the
UIView 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.