SwiftUI: unwanted split view on iPad

后端 未结 2 1530
自闭症患者
自闭症患者 2020-12-14 06:53

Problem: a view on Pad shows up with unwanted split view.

My current setup is: Catalina OSX beta 5 + Xcode 11 Beta 5

Here is the c

相关标签:
2条回答
  • 2020-12-14 06:58

    You can apply the .navigationViewStyle(StackNavigationViewStyle()) modifier to the NavigationView!

    ... 
        NavigationView {
            Text("Hello world!")
        }
        .navigationViewStyle(StackNavigationViewStyle())
    ...
    

    Edit: Below, I am answering Alexandre's questions from his comment:

    • Why full view is not the default for iPad? That's just a choice made by Apple...

    • Why this modifier goes outside of NavigationView closure, while the Navigation Title goes inside... Maybe this gives clarification: https://stackoverflow.com/a/57400873/11432719

    0 讨论(0)
  • 2020-12-14 07:19

    To use this split style for iPad but remove for iPhone:

        extension View{
        func phoneOnlyStackNavigationView() ->some View{
    
            if UIDevice.current.userInterfaceIdiom == .phone{
                return AnyView(self.navigationViewStyle(StackNavigationViewStyle()))
            }else{
                return AnyView(self)
            }
        }
    }
    
    0 讨论(0)
提交回复
热议问题