小编Dev*_*ley的帖子

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

通过赋予它自己的观点,我已经成功地将 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: …
Run Code Online (Sandbox Code Playgroud)

swift lottie lottie-ios swiftui

3
推荐指数
1
解决办法
1056
查看次数

标签 统计

lottie ×1

lottie-ios ×1

swift ×1

swiftui ×1