Dev*_*ley 3 swift lottie lottie-ios swiftui
通过赋予它自己的观点,我已经成功地将 Lottie 应用到我的程序中。虽然一旦被调用,动画只播放一次。我将如何使动画循环?谢谢你。
LottieView(与 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>) {
}
}
Run Code Online (Sandbox Code Playgroud)
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)
}
}
Run Code Online (Sandbox Code Playgroud)
小智 6
您可以为播放调用设置循环行为。在里面添加这段代码makeUIView(context:)
animationView.loopMode = .loop
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1056 次 |
| 最近记录: |