UIView.animate: What It Is, Animating UIView Properties in iOS

Author: IT Sectr Published: 2026-03-01 Reading time: 8 min

UIView.animate is the main method for animating UIView properties in iOS, implemented in UIKit through blocks with duration, delay, and options. The method animates frame, alpha, transform, backgroundColor, and other animatable properties. This article describes the syntax, parameters, practical examples, and the internal structure of UIKit animations.

Key Takeaways

  • UIView.animate — a block-based method for animating UIView properties: frame, alpha, transform, backgroundColor
  • Parameters — duration (sec), delay (sec), options (curve, repeat, autoreverse), completion (closure)
  • Spring Animation — UIView.animate(withDuration:delay:usingSpringWithDamping:) with physical bounce
  • Keyframe Animation — UIView.animateKeyframes for multi-step sequences with relative timing
  • Core Animation — under the hood, UIView.animate uses CABasicAnimation at the CALayer level

What Is UIView.animate?

UIView.animate is a static method of the UIView class, introduced in iOS 4 (2010). It provides a declarative API for animating animatable properties of UIView: frame, bounds, center, alpha, transform, backgroundColor. The method accepts a block (closure) with property changes — the system automatically creates CABasicAnimation for each changed property.

The block syntax replaced the old beginAnimations/commitAnimations (iOS 2-3) and became the animation standard in UIKit. UIView.animate animations run on the main thread and do not block the UI. By default, the animation duration is 0.25 seconds with an easeInOut curve.

According to Apple WWDC 2023, the recommended animation approach in new projects is SwiftUI with .animation() and .transition() modifiers, but UIView.animate remains the primary tool for iOS 16 and below support, as well as for complex custom transitions.

Animation Parameters and Options

UIView.animate provides three key parameters: duration (length in seconds), delay (delay before start), and options (set of UIView.AnimationOptions bit masks). Options include curve (easeInOut, easeIn, easeOut, linear), repeat, autoreverse, allowUserInteraction, beginFromCurrentState, and overrideInheritedDuration.

ParameterTypeDescription
durationTimeIntervalAnimation length in seconds (Double type)
delayTimeIntervalDelay before animation starts
optionsUIView.AnimationOptionsBit mask: curve, repeat, autoreverse, layoutSubviews
animations() -> VoidBlock with changes to animatable properties
completion(Bool) -> VoidClosure after animation completion

The options parameter is combined via an array: [.curveEaseOut, .repeat, .autoreverse]. Animation with repeat and autoreverse smoothly returns the View to its initial state and repeats indefinitely. For a finite number of repetitions, use animateKeyframes.

Spring Animation via UIView.animate

Spring animation adds a physical spring effect: the object doesn't just move from point A to B, but overshoots the target with damped oscillations. Parameters: usingSpringWithDamping (damping 0-1, where 0 is maximum oscillation) and initialSpringVelocity (initial spring velocity).

Apple recommends usingSpringWithDamping in the range of 0.4-0.8 for natural UI animations. A value of 0.5 creates noticeable bounce without feeling "rubbery." initialSpringVelocity = 1.0 corresponds to a speed of 1 pt/sec. At 0, the animation starts from rest.

swift
// Spring animation and keyframe example
import UIKit

class AnimatedView: UIView {

    func springBounce() {
        // Spring animation with damping
        UIView.animate(
            withDuration: 0.8,
            delay: 0,
            usingSpringWithDamping: 0.5,
            initialSpringVelocity: 1.0,
            options: [.allowUserInteraction],
            animations: {
                self.transform = CGAffineTransform(scaleX: 1.2, y: 1.2)
                self.alpha = 0.7
            },
            completion: { _ in
                UIView.animate(withDuration: 0.3) {
                    self.transform = .identity
                    self.alpha = 1.0
                }
            }
        )
    }

    func slideIn(from offset: CGFloat) {
        self.transform = CGAffineTransform(translationX: offset, y: 0)
        self.alpha = 0.0

        UIView.animate(
            withDuration: 0.6,
            delay: 0.1,
            options: [.curveEaseOut]
        ) {
            self.transform = .identity
            self.alpha = 1.0
        }
    }
}

Keyframe Animation

UIView.animateKeyframes allows you to break an animation into multiple steps (keyframes), each with its own relative time and duration. The addKeyframe(withRelativeStartTime:relativeDuration:) method accepts time values from 0 to 1 relative to the total animation duration.

Keyframe animations are useful for multi-stage effects: button pulse (increase → pause → return), sequential element appearance, complex deformations with intermediate states. Each keyframe can have its own animation curve via options.

swift
// Keyframe animation with complex sequence
func complexPulse() {
    UIView.animateKeyframes(withDuration: 2.0, delay: 0, options: [.repeat]) {
        UIView.addKeyframe(withRelativeStartTime: 0.0, relativeDuration: 0.25) {
            self.transform = CGAffineTransform(scaleX: 1.5, y: 1.5)
            self.alpha = 0.5
        }
        UIView.addKeyframe(withRelativeStartTime: 0.25, relativeDuration: 0.25) {
            self.transform = CGAffineTransform(scaleX: 0.8, y: 0.8)
            self.alpha = 0.8
        }
        UIView.addKeyframe(withRelativeStartTime: 0.5, relativeDuration: 0.5) {
            self.transform = .identity
            self.alpha = 1.0
        }
    }
}

// Animation with nested closures
func animateCardTransition() {
    UIView.animate(withDuration: 0.4, delay: 0, options: [.curveEaseOut]) {
        self.transform = CGAffineTransform(scaleX: 0.95, y: 0.95)
    } completion: { _ in
        UIView.animate(withDuration: 0.3, delay: 0, options: [.curveEaseIn]) {
            self.transform = .identity
        }
    }
}

Internal Structure: Core Animation Under the Hood

Under the hood, UIView.animate delegates animation to the CALayer of each UIView through Core Animation (CAAnimation). When you change the frame inside the animation block, the system creates CABasicAnimation for the position and bounds properties of the corresponding layer. If alpha is changed — CABasicAnimation for the layer's opacity property.

Core Animation uses a separate render server process (backboardd on iOS) that processes animations at 120 Hz (ProMotion). UIView.animate does not block the main thread — property changes are sent to the render server, which interpolates frames without application involvement.

According to Apple, animations via UIView.animate have an overhead of ~2-3% CPU per changed layer at 60 FPS. For mass animations (20+ objects simultaneously), it is recommended to use CATransaction and manual layer management.

For debugging and visualizing UIKit animations, use Xcode Debug View Hierarchy — it shows active CAAnimations on each layer, their duration, curve, and current state. Understanding the internal structure of Core Animation helps avoid performance issues with complex animations and choose the optimal approach between UIView.animate and direct use of CABasicAnimation.

For debugging and visualizing UIKit animations, use Xcode Debug View Hierarchy — it shows active CAAnimations on each layer, their duration, curve, and current state. Understanding the internal structure of Core Animation helps avoid performance issues with complex animations and choose the optimal approach between UIView.animate and direct use of CABasicAnimation.

Frequently Asked Questions

What UIView properties can be animated?

Animatable properties of UIView: frame, bounds, center, alpha, transform (CGAffineTransform), backgroundColor. Changes to layoutIfNeeded() when modifying Auto Layout constraints are also animated. Other properties cannot be animated through UIView.animate — use CALayer or CADisplayLink for those.

How is UIView.animate different from UIView.animateKeyframes?

UIView.animate performs one animation from the current state to the target state. UIView.animateKeyframes splits the total duration into several steps (keyframes) with different relative start times and durations. Keyframes are suitable for multi-stage sequences.

Why doesn't UIView.animate block the UI?

UIView.animate animations are processed in the render server (backboardd) — a separate iOS process. The main thread only sends the initial and final property values. Frame interpolation is performed on the GPU through Core Animation at up to 120 FPS.

How to stop UIView.animate before completion?

Call layer.removeAllAnimations() on the UIView — this removes all CAAnimations created under the hood. For more precise control, use CATransaction and animation identifiers via CAAnimation.keyPath.

Summary

  • UIView.animate — block-based method for animating UIView properties with duration, delay, options, and completion
  • Spring animation — usingSpringWithDamping + initialSpringVelocity for physical bounce
  • Keyframe animation — UIView.animateKeyframes with addKeyframe for multi-step sequences
  • Animatable properties — frame, bounds, center, alpha, transform, backgroundColor
  • Core Animation — under the hood, UIView.animate creates CABasicAnimation for CALayer
  • Render server — animations are processed at 120 Hz without blocking the main thread
  • SwiftUI — recommended tool for new projects, UIView.animate for iOS 16- support

We will develop a mobile application turnkey

IT Sectr creates iOS and Android applications for startups and businesses since 2017. We will advise you and propose the best solution.

Discuss the project

Read also