Lottie 在 iOS 上与用户互动

Lottie with user interaction on iOS

在我的 iOS 应用程序中,我有整个屏幕上的 lottie 动画。在动画期间,用户交互不可用。我想让动画下的所有内容都对用户交互(滚动、按钮等)有效 有机会做吗?

代码:

guard let mainView = self?.view, let animationView = LOTAnimationView(name: "someName") else { return }

animationView.frame = CGRect(x: 0,
                             y: 0,
                         width: mainView.frame.size.width,
                        height: mainView.frame.size.height)

animationView.contentMode = .scaleAspectFill
animationView.loopAnimation = false

mainView.addSubview(animationView)

animationView.play() { _ in
    animationView.removeFromSuperview()
}

您是否尝试过将手势识别器添加到 Lottie 视图?

附加代码后编辑:

您可以尝试将 gestureRecognizer 添加到 animationView 并在您的函数中添加参数 (sender)。

func handleTap(sender: UITapGestureRecognizer) {
    if sender.state == .ended {
        // handling code
    }
}

我打赌禁用动画视图的用户交互会成功。尝试类似的东西: animationView.userInteractionEnabled = false。这应该可以防止触摸被 animationView 消耗并且不会向下传播到视图层次结构。