SwiftUI NavigationView on the iPad Pro

前端 未结 6 846
伪装坚强ぢ
伪装坚强ぢ 2020-12-28 13:09

I use the Apple SwiftUI tutorial code. Then I set the previewDevice to iPad Pro (12.9-inch). But the preview has something wrong. Does anyone know where the problem is?

6条回答
  •  一向
    一向 (楼主)
    2020-12-28 13:28

    Using the code provided by nalexn I came up with this as the solution.

    As commented by matthew in the same post iPhones in landscape mode will still cause the drawer to be hidden thus, using StackNavigationViewStyle() is more suitable for iPhone whilst for iPad it will use the DoubleColumnNavigationViewStyle()

        var body: some View {
        GeometryReader{ geo in
          if (UIDevice.current.userInterfaceIdiom == .pad){
            NavigationView{
              self.makeContents()
            }.navigationViewStyle(DoubleColumnNavigationViewStyle())
              .padding(.leading, geo.size.width < geo.size.height ? 0.25 : 0)
          }else{
            NavigationView{
              self.makeContents()
            }.navigationViewStyle(StackNavigationViewStyle())
          }
        }
      }
    

    Hope this helps anyone that comes to this post after me :D

提交回复
热议问题