Swift 中 UIRefreshControl 子视图中的 Lottie 动画出现故障

发布于 2025-01-16 04:07:26 字数 1344 浏览 2 评论 0原文

我正在尝试在scrollview.refreshControl的子视图中加载Lottie动画,该动画出现在拉动刷新上,但出现故障,这使得动画看起来不流畅并且似乎有很多错误。

我在 viewDidLoad 中使用的代码:

let loadingView : AnimationView = {
        let view = AnimationView()
        view.translatesAutoresizingMaskIntoConstraints = false
        view.animation = Animation.named("loading-dots-blue")
        view.loopMode = .loop
        view.contentMode = .scaleAspectFill
        view.play()
        return view
    }()
    
    scrollView.refreshControl = UIRefreshControl()
    scrollView.refreshControl?.addTarget(self, action: #selector(self.refresh(_:)), for: .valueChanged)
    
    scrollView.refreshControl!.addSubview(loadingView)
    scrollView.refreshControl?.tintColor = .clear
    
    loadingView.centerXAnchor.constraint(equalTo: scrollView.refreshControl!.centerXAnchor).isActive = true
    loadingView.centerYAnchor.constraint(equalTo: scrollView.refreshControl!.centerYAnchor).isActive = true
    loadingView.widthAnchor.constraint(equalToConstant: UIScreen.main.bounds.width/2).isActive = true
    loadingView.heightAnchor.constraint(equalToConstant: 50).isActive = true

the glitchy loader

这只发生在 Lottie 动画上,默认的 ActivityIndi​​cator 看起来动画很流畅。

I am trying to load a Lottie animation in the subview of scrollview.refreshControl, the animation appears on the pull to refresh but is glitching which makes the animation look not smooth and appears to be very buggy.

the code that I am using in viewDidLoad:

let loadingView : AnimationView = {
        let view = AnimationView()
        view.translatesAutoresizingMaskIntoConstraints = false
        view.animation = Animation.named("loading-dots-blue")
        view.loopMode = .loop
        view.contentMode = .scaleAspectFill
        view.play()
        return view
    }()
    
    scrollView.refreshControl = UIRefreshControl()
    scrollView.refreshControl?.addTarget(self, action: #selector(self.refresh(_:)), for: .valueChanged)
    
    scrollView.refreshControl!.addSubview(loadingView)
    scrollView.refreshControl?.tintColor = .clear
    
    loadingView.centerXAnchor.constraint(equalTo: scrollView.refreshControl!.centerXAnchor).isActive = true
    loadingView.centerYAnchor.constraint(equalTo: scrollView.refreshControl!.centerYAnchor).isActive = true
    loadingView.widthAnchor.constraint(equalToConstant: UIScreen.main.bounds.width/2).isActive = true
    loadingView.heightAnchor.constraint(equalToConstant: 50).isActive = true

the glitchy loader

This only occurs on lottie animation, the default activityIndicator appears to be animating smoothly.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

只是一片海 2025-01-23 04:07:26

通过将滚动视图顶部约束从安全区域更改为超级视图,已解决了 Lottie 动画问题。虽然我之前使用默认活动指示器实现了此解决方案,但当我将lottie动画添加到uirefreshcontrol时,它以某种方式变回安全区域。

输入图片这里的描述

我在 StackOverflow 上找到的原始答案:
https://stackoverflow.com/a/54629641/14352175

The glitchy Lottie animation issue has been resolved by changing the scrollview top constraint from safe area to superview. Although I implemented this solution before with the default activity indicator but somehow it changed back to safe area when I added the lottie animation to the uirefreshcontrol.

enter image description here

The original answer I found on StackOverflow:
https://stackoverflow.com/a/54629641/14352175

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文