繁体   English   中英

隐藏 ScrollView 内的 SwiftUI LazyHStack TabView

[英]SwiftUI LazyHStack TabView inside ScrollView is hidden

我有以下观点:

#if DEBUG
struct MyTestView_Previews: PreviewProvider {
    static var previews: some View {
        MyTestView()
    }
}
#endif

struct MyTestView: View {
    @State var selectedTab: Int = 0

    var body: some View {
        GeometryReader { geometry in
            VStack(spacing: 0) {
                ScrollView {
                    LazyHStack {
                        TabView(selection: $selectedTab) {
                            ForEach(0...3, id: \.self) { i in
                                Text(String(i))
                            }
                        }
                        .animation(.easeInOut)
                        .frame(width: UIScreen.main.bounds.width)
                        .tabViewStyle(PageTabViewStyle(indexDisplayMode: .never))
                    }
                }

                Spacer().frame(height: geometry.safeAreaInsets.bottom)
            }
            .navigationBarTitle("Test")
            .edgesIgnoringSafeArea(.bottom)
        }
    }
}

这曾经在 XCode 13 和 iOS 15 之前运行良好。现在使用最新版本,我的 TabView 项目不再显示。 在所有。 如果我删除了ScrollView ,它在我的真实场景中为我提供了必要的垂直滚动,我可以再次看到我的项目。

如何在LazyHStack -> TabView场景中进行垂直滚动?

一天后,我想我可以将我的 ScrollView 向下移动:

struct MyTestView: View {
    @State var selectedTab: Int = 0

    var body: some View {
        GeometryReader { geometry in
            VStack(spacing: 0) {
                LazyHStack {
                    TabView(selection: $selectedTab) {
                        ForEach(0...3, id: \.self) { i in
                            ScrollView {
                                Text(String(i))
                            }
                        }
                    }
                    .animation(.easeInOut)
                    .frame(width: UIScreen.main.bounds.width)
                    .tabViewStyle(PageTabViewStyle(indexDisplayMode: .never))
                }

                Spacer().frame(height: geometry.safeAreaInsets.bottom)
            }
            .navigationBarTitle("Test")
            .edgesIgnoringSafeArea(.bottom)
        }
    }
}

现在一切正常。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM