Automatic Touch Handling
When you use a Rive animation with a state machine that has listeners, touch events are handled automatically:Multiple Interactive Animations
You can easily display multiple interactive animations:Touch Event Delegates
For more control, implement theRiveStateMachineDelegate protocol to receive touch event callbacks:
Using the Delegate
- UIKit
- AppKit (macOS)
Hit Testing
Receive information about what was hit during touch events:Receiving Rive Events
Listen for custom events fired from your Rive animations:State Machine State Changes
Monitor when the state machine changes states:State Machine Input Changes
Receive notifications when inputs change:Forwarding Touch Events
By default, Rive views consume touch events. To allow touch events to pass through to views behind the Rive view:- You have a semi-transparent animation over other UI
- You want gesture recognizers to work alongside Rive interactions
- You need to handle events in parent views
Platform-Specific Touch Handling
iOS/visionOS
macOS
- Touch events are actually mouse events
- The same delegate methods work
- Mouse tracking is set up automatically
- Dragging is supported through
touchMoved
Complete Delegate Protocol
All availableRiveStateMachineDelegate methods:
Best Practices
- Use State Machines - Touch events require state machines with listeners configured in the Rive editor
- Test on Device - Touch interactions may feel different on device vs simulator
- Handle All States - Implement both
touchBeganandtouchEndedfor complete interactions - Consider Hit Areas - Make interactive areas large enough for comfortable tapping (44x44pt minimum on iOS)
- Provide Feedback - Use Rive events to provide haptic or audio feedback
- Forward Events Carefully - Only enable
forwardsListenerEventswhen needed to avoid conflicts - Clean Up Delegates - Set delegates to nil in
deinitto avoid retain cycles
Common Patterns
Button-Like Interaction
Drag Interaction
Next Steps
- SwiftUI Guide - Using Rive with SwiftUI
- UIKit Guide - Using Rive with UIKit
- AppKit Guide - Using Rive with AppKit
- RiveStateMachineInstance API - Complete API documentation