chore: 播放动画容器调整

This commit is contained in:
Junhui Chen 2025-09-12 14:51:49 +08:00
parent c4c33158fd
commit 7adf475b8f

View File

@ -7,25 +7,43 @@ struct BlindBoxLottieOnceView: UIViewRepresentable {
var animationSpeed: CGFloat = 1.0
let onCompleted: () -> Void
func makeUIView(context: Context) -> LottieAnimationView {
func makeUIView(context: Context) -> UIView {
// LottieView
let container = UIView()
container.clipsToBounds = true
let animationView = LottieAnimationView()
animationView.translatesAutoresizingMaskIntoConstraints = false
if let animation = LottieAnimation.named(name) {
animationView.animation = animation
} else if let path = Bundle.main.path(forResource: name, ofType: "json") {
let animation = LottieAnimation.filepath(path)
animationView.animation = animation
}
animationView.loopMode = .playOnce
animationView.animationSpeed = animationSpeed
animationView.contentMode = .scaleAspectFit
animationView.backgroundBehavior = .pauseAndRestore
container.addSubview(animationView)
NSLayoutConstraint.activate([
animationView.leadingAnchor.constraint(equalTo: container.leadingAnchor),
animationView.trailingAnchor.constraint(equalTo: container.trailingAnchor),
animationView.topAnchor.constraint(equalTo: container.topAnchor),
animationView.bottomAnchor.constraint(equalTo: container.bottomAnchor)
])
//
animationView.play { _ in
onCompleted()
}
return animationView
return container
}
func updateUIView(_ uiView: LottieAnimationView, context: Context) {
func updateUIView(_ uiView: UIView, context: Context) {
//
}
}