I have successfully implemented Lottie into my program by giving it its own view. Although once called, the animation only plays once. How would I make it so the animation loops?
LottieView (View with Lottie):
import SwiftUI
import Lottie
struct LottieView: UIViewRepresentable {
typealias UIViewType = UIView
var filename: String
func makeUIView(context: UIViewRepresentableContext<LottieView>) -> UIView {
let view = UIView(frame: .zero)
let animationView = AnimationView()
let animation = Animation.named(filename)
animationView.animation = animation
animationView.contentMode = .scaleAspectFit
animationView.play()
animationView.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(animationView)
NSLayoutConstraint.activate([
animationView.widthAnchor.constraint(equalTo: view.widthAnchor), animationView.heightAnchor.constraint(equalTo: view.heightAnchor)
])
return view
}
func updateUIView(_ uiView: UIView, context: UIViewRepresentableContext<LottieView>) {
}
}
Current Implementation in ContentView:
HStack {
if isScroll {
LottieView(filename: "swipeLeft").frame(width: 200, height: 200)
.padding(.top, 500)
.padding(.leading, 100)
}
Spacer()
Button(action: {
SCLAlertView().showInfo("How to use:", subTitle: "Scroll across the screen to view panels. Then press on a panel to view more information.")
}) {
Image(systemName: "info.circle")
.padding(.trailing, 5)
.padding(.top, 400)
}
}
loopMode
property to.loop
for your views of typeAnimationView
. – Petroglyph