本文介绍了iOS 14.2中的SwiftUI PageTabView滞后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将TabView和PageTabViewStyle一起使用,每个子视图都包含一个具有大数据集的列表视图.

I'm using TabView with PageTabViewStyle, and each child view comprises a list view with a large data set.

仅在iOS 14.2上,页面转换似乎非常缓慢.

Only on iOS 14.2, the page transitions seem to be very laggy.

但是,列表转换在具有少量数据的列表视图中不会延迟.

However, page transitions are not delayed in list views with a small amount of data.

我猜是因为列表行显示是惰性的,所以TabView包含列表的性能将独立于数据量.

It's my guess that the performance of TabView comprises list would be independent of the amount of data, because of the list row display is lazy.

所以,我认为这是错误或默认的视图样式更改.

So, I believe it is bugs or default view style changes.

我期待着您的帮助解决此问题.谢谢

I look forward to your help to solve this problem. Thank you

@available(iOS 14.0, *)
struct ContentView: View {
    @State var showHeart: Bool = false
    var body: some View {
        TabView{
            self.contents
            self.contents
        }
        .tabViewStyle(PageTabViewStyle())
    }
    var contents: some View{
        List(0..<1000){_ in
            Text("HELLO WORLD HELLOWORLD")
        }
    }
}

推荐答案

我一直在玩这个游戏,这只是一个发现-当您使用 TabView()时,它会很慢,但是如果您添加一个绑定作为 TabView(selection:$ selection)传递,只是对选择绑定不做任何事情,它以某种方式不再滞后了?哈克,但一个解决方案.

I have been playing with this and just a discovery - when you use TabView() it is laggy, but if you add a binding passed as TabView(selection: $selection) and just don't do anything with the selection binding it somehow doesn't lag anymore? Hacky, but a solution.

这篇关于iOS 14.2中的SwiftUI PageTabView滞后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 12:17