Reputation: 1995
I'm trying to use Lottie animations inside my ios app but I can't get them to work. I've seen people use LOTAnimationViews
but I can't import or use this class. I've added an Animation folder with my animations in.
ViewController:
class CardStackViewController: UIViewController, CLLocationManagerDelegate, NetworkManagerDelegate {
...
private let animationView = AnimationView()
...
...
func didFail(with error: Error) {
if let animation = Animation.named("error", subdirectory: "Animations") {
animationView.animation = animation
animationView.loopMode = .loop
view.addSubview(animationView)
animationView.play()
}
print("---DIDFAIL WITH ERROR---", error.localizedDescription, error)
}
...
}
Upvotes: 0
Views: 1211
Reputation: 5223
If are want to achieve it using a storyboard, follow these steps:
Now in your ViewController class, import Lottie and create an outlet like this:
import Lottie
class YourVC : UIViewController {
@IBOutlet weak var myAnimationView : AnimationView!
}
Now in your ViewDidLoad function setup your animation like this:
let animationToShow = Animation.named("yourAnimationFileNameWithoutJSONextension")
myAnimationView.animation = animationToShow
myAnimationView.animationSpeed = 1.0
myAnimationView.loopMode = .loop
myAnimationView.contentMode = .scaleAspectFit
myAnimationView.play()
Done!
Upvotes: 1
Reputation: 100533
Above
import lottie
and give the view a frame
animationView.animation = animation
animationView.frame = ///
Upvotes: 2