Animations
Add motion to your app’s interface to entertain or provide feedback.
Animate the views in your interface
Apps use view-based animations to convey what’s going on, so consider the role that animations play in your app’s interface. Many standard views use animations to convey appearance changes. For example, buttons animate changes for hover events or when someone taps or clicks them. You can add custom animations to support other types of interactions with your content.
If you’re creating a game or immersive experience, frequent animations might be an inherent part of your content. If you’re drawing all of your game’s content, animations are implicit. For apps with 3D content, consider using RealityKit to animate your content instead of drawing everything yourself.
Animate the views in your interface
View-based animations convey the state of your app, provide feedback and instruction, and enrich people’s experience with your app. When you use standard system views, you get many animations for free. For example, Navigation in SwiftUI, and view controllers in View controllers and View Management use animations to show transitions between different parts of the interface. If you use these types in your interface, don’t modify or change the built-in animations, which have specific and well-defined meanings.
If you’re defining a new way to present content, consider how you can use animations to support transitions. You can make views appear or disappear, change their visibility, scale or rotate them, and more by changing the view’s built-in attributes. To animate those changes, wrap them in system-provided animation APIs. The following examples use the animation APIs for Animations, Animation and haptics, and Animation to change the view’s position along the y-axis. The effect causes the view to bounce up and back down, returning to its original position.
An alternative approach is to animate UIKit and AppKit content with Core Animation. UIView and NSView use Core Animation CALayer to manage the pixels they display. A layer is a lightweight type that accelerates drawing-related tasks, including animations. You can use layers to manage image-based content that doesn’t require frequent redrawing. Use the Core Animation APIs when you want more precise control over your layer and view-based animations.
Animate 2D content
If your app’s content is entirely custom, and doesn’t rely on standard views, draw everything yourself using Metal. You typically use Metal for games, media apps, productivity apps, or content that people create themselves. For example, use it to implement a whiteboard app that supports custom content creation using a variety of different brushes, tools, and creation modes. Only Metal offers the performance you need to animate large amounts of custom content smoothly.
Animate 3D content
If you create 3D content and scenes in advance, you can use RealityKit to display and animate that content. RealityKit provides high-performance simulation and rendering capabilities for 3D content. The RealityKit architecture uses an Understanding the modular architecture of RealityKit (ECS) architecture to manage content and apply animations and other changes efficiently. Instead of modifying your content, modify components that influence the content. For example, change the position, size, and orientation of an object in your scene by modifying its Transform. RealityKit takes the component values you provide and applies them to your content during rendering.
When you need raw performance, build your own 3D rendering engine using Metal. When you use Metal for drawing, you control what you draw and how you draw it, and Metal runs your code with minimal overhead on the GPU. Use Metal to achieve 3D scenes with realistic lighting, textures, and even special effects like smoke, lens flares, motion blurs, and more.