gpt4 book ai didi

SwiftUI:如何制作 Lottie 动画循环?

转载 作者:行者123 更新时间:2023-12-04 00:55:56 28 4
gpt4 key购买 nike

通过赋予它自己的观点,我已经成功地将 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>) {

}




}
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)

}


}

最佳答案

您可以为播放调用设置循环行为。在 makeUIView(context:) 中添加此代码

animationView.loopMode = .loop

关于SwiftUI:如何制作 Lottie 动画循环?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62584516/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com