Embed interactive Rive animated icons in your iOS or iPadOS app using RiveViewModel and the Rive Swift Package.
In Xcode, go to your project settings → Package Dependencies and add the Rive iOS package.
Import RiveRuntime, create a RiveViewModel with your file name and state machine, then add the view to your layout.
import RiveRuntime
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let riveModel = RiveViewModel(
fileName: "your_animation",
stateMachineName: "State Machine 1"
)
let riveView = riveModel.createRiveView()
riveView.frame = CGRect(x: 100, y: 100, width: 150, height: 150)
view.addSubview(riveView)
}
}Use the RiveViewModel to trigger animations and set boolean inputs in response to user interactions.
// Fire a trigger input
riveModel.triggerInput("Trigger")
// Set a boolean input
riveModel.setBooleanInput("Hover", value: true)
// Read an input value
let isActive = riveModel.getBooleanInput("IsActive")