旋转时导航栏中的SwiftUI滚动视图

时间:2020-05-28 17:21:05

标签: ios swiftui

in this post与GeometryReader苦苦挣扎之后,感谢@Asperi的帮助,我前进了。

但是我现在遇到另一个与GeometryReader无关的问题:当我将设备转到横向时,滚动视图的顶部在NavigationBar下显示

enter image description here 似乎是一种很不稳定的行为,但是有人知道对此有确定的解决方法吗? (在物理iPad Pro 11和iPhone X上进行了测试)

这是代码(使用Asperi的言论从原始帖子中修改)


struct ContentView: View {

    let arrayWithStuff = [ "one","two","three","four","five","six","seven","eight","nine","ten", "eleven", "twelve"]

    var body: some View {

    let myString = "Top of Test App"

     return   ZStack {
        GeometryReader { g in
            NavigationView {
                ScrollView {
                    VStack {
                        Text(myString)
                            .padding()
                            .background(Color.blue)
                    Divider()
                        self.ViewBody(inputHeight: g.size.height)
                } // END of Vstack
                    .navigationBarTitle("Test App", displayMode: .inline)
                } // END of Scrollview
                    .background(Color.clear)
                }//End of NavigationView
                    .background(Color.clear)
                    .navigationViewStyle(StackNavigationViewStyle())
                } // End of Geometry reader
            } // End of Zstack

  } // End of body


    func ViewBody(inputHeight: CGFloat) -> some View {
        print("height of view : \(inputHeight)")
        return VStack {
            List {
                ForEach (self.arrayWithStuff, id: \.self) { item in
                    Text(item) }
            } // END of List
                .frame(height: inputHeight*0.5)
                .background(Color.pink)
            Divider()
            Text("Bottom of TEST APP")
                .background(Color.orange)
        }
        .padding()
    }
}

最诚挚的问候,

0 个答案:

没有答案