RiveViewModel and RiveView APIs used on other platforms. This guide covers macOS-specific integration patterns.
Quick Start
Using Rive in SwiftUI on macOS is identical to iOS:AppKit Integration
Programmatic Setup
Using Interface Builder
1. Add an NSView to your XIB or Storyboard 2. Set the custom class:- Select the view in Interface Builder
- Open the Identity Inspector
- Set Class to
RiveView - Set Module to
RiveRuntime
Mouse Events
Rive automatically handles mouse events on macOS:Window and Screen Management
Display Scale Factor
Rive automatically handles Retina displays and window movements between screens with different resolutions:Custom Scale Factor
For.layout fit mode, you can override the automatic scale detection:
Frame Rate Control (macOS 14+)
Preferred Frame Rate
Frame Rate Range
Controlling Animations
Playback Controls
State Machine Inputs
Layout Configuration
Fit and Alignment
SwiftUI on macOS
The SwiftUI API is identical to iOS:View Controllers vs SwiftUI
- AppKit (NSViewController)
- SwiftUI
Lifecycle Management
Best Practices
- Handle Window Movement - Rive automatically handles screen changes, but be aware of performance on lower-resolution displays
- Use Autoresizing Masks or Constraints - Ensure your RiveView resizes properly with the window
- Pause When Inactive - Pause animations in
viewWillDisappearto conserve resources - Frame Rate Optimization - Use frame rate controls (macOS 14+) for better performance on battery
- Memory Management - Clean up view models in
deinit - Dark Mode Support - Rive animations respect the system appearance automatically
Platform-Specific Considerations
Mouse vs Touch
- macOS uses mouse events (
mouseDown,mouseMoved,mouseUp) - Delegate methods use generic names (
touchBegan,touchMoved,touchEnded) - The same delegate protocol works across all platforms
Display Sync
- macOS 14+ uses
CADisplayLinkfor smooth rendering - Earlier versions use
CVDisplayLink - Both provide synchronized updates with the display refresh rate
Performance
- ProMotion displays (120Hz) are automatically supported on compatible Macs
- Consider setting frame rate limits for battery-powered devices
- Use
.layoutfit mode carefully on high-resolution displays
Next Steps
- Loading Assets - Learn how to load .riv files from different sources
- Touch Events - Handle mouse and touch interactions (same API across platforms)
- RiveViewModel API - Complete API documentation