SwiftUI NavigationView on the iPad Pro

前端 未结 6 838
伪装坚强ぢ
伪装坚强ぢ 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:16

    It looks like the master view (the one on the left) is hidden on iPads running iOS 13 by design. The master view is there, you can pull it out from the left edge of the screen.

    Unfortunately, there is currently no API to opt-out of this behavior other than applying a non-zero padding for the leading edge:

    var body: some View {
        GeometryReader { geometry in
            NavigationView {
                self.content
            }.padding(.leading, self.leadingPadding(geometry))
        }
    }
    
    private func leadingPadding(_ geometry: GeometryProxy) -> CGFloat {
        if UIDevice.current.userInterfaceIdiom == .pad {
            // A hack for correct display of the SplitView in SwiftUI on iPad
            return geometry.size.width < geometry.size.height ? 0.5 : -0.5
        }
        return 0
    }
    

提交回复
热议问题