Swift 中 UIRefreshControl 子视图中的 Lottie 动画出现故障
我正在尝试在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
这只发生在 Lottie 动画上,默认的 ActivityIndicator 看起来动画很流畅。
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
This only occurs on lottie animation, the default activityIndicator appears to be animating smoothly.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通过将滚动视图顶部约束从安全区域更改为超级视图,已解决了 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.
The original answer I found on StackOverflow:
https://stackoverflow.com/a/54629641/14352175