iOS
iOS runtime for Rive

Overview

This guide documents how to get started using the iOS runtime library. Rive runtime libraries are open-source. The source is available in its GitHub repository. This library contains an API for iOS apps to easily integrate their Rive assets for both UIKit and SwiftUI. The runtime can also be installed via Cocoapods or Swift Package Manager.
The minimum iOS target is 14.0

Getting Started

Follow the steps below for a quick start on integrating Rive into your iOS app.

1. Install the dependency

Via Cocoapods

Add the following to your Podspec file:
Podfile
1
pod 'RiveRuntime'
Copied!

Via Swift Package Manager

To install via Swift Package Manager, in the package finder in xcode, search with the Github repository name: https://github.com/rive-app/rive-ios

2. Importing Rive

Add the following to the top of your file where you utilize the Rive runtime:
1
import RiveRuntime
Copied!

3. v2 Runtime Usage

Rive iOS runtimes of versions 2.x.x or later should use the newer patterns for integrating Rive into your iOS applications. This involves some API changes from the pattern in versions 1.x.x (see migration guide for guidance on moving to 2.x.x). The primary object you'll use is a RiveViewModel. It is responsible for creating and interacting with Rive assets.

3a. SwiftUI

Set up RiveViewModel w/ View
1
struct AnimationView: View {
2
var body: some View {
3
RiveViewModel(fileName: "cool_rive_animation").view()
4
}
5
}
Copied!

3b. UIKit - Storyboard

Set up RiveViewModel w/ Controller formatted on a Storyboard

The simplest way of adding Rive to a controller using Storyboards is to make a RiveViewModel, and set its view to be the RiveView you made in the Storyboard.
1
class AnimationViewController: UIViewController {
2
@IBOutlet weak var riveView: RiveView!
3
var simpleVM = RiveViewModel(fileName: "cool_rive_animation")
4
5
override public func viewDidLoad() {
6
simpleVM.setView(riveView)
7
}
8
}
Copied!

3c. UIKit - Programmatic

Set up RiveViewModel w/ Controller from scratch in code

You can also add Rive to a controller purely with code by making the RiveViewModel, telling it to create a fresh RiveView and then adding it to the view hierarchy.
1
class AnimationViewController: UIViewController {
2
var simpleVM = RiveViewModel(fileName: "cool_rive_animation")
3
4
override func viewWillAppear(_ animated: Bool) {
5
let riveView = simpleVM.createRiveView()
6
view.addSubview(riveView)
7
riveView.frame = view.frame
8
}
9
}
Copied!
See subsequent runtime pages to learn how to control animation playback, state machines, and more.

Resources