Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SwiftUI: unwanted split view on iPad

People also ask

How do I get rid of split screen on IPAD search?

To close Split View, tap the Multitasking button in the Safari window that you want to keep, then tap the full screen button . Or you can drag the app divider left or right over the Safari window that you want to close.

What is Stacknavigationviewstyle?

A navigation view style represented by a view stack that only shows a single top view at a time.

How do I navigate in SwiftUI?

SwiftUI's NavigationLink has a second initializer that has an isActive parameter, allowing us to read or write whether the navigation link is currently active. In practical terms, this means we can programmatically trigger the activation of a navigation link by setting whatever state it's watching to true.

How do you split view in Xcode?

Xcode 10 and earlier. Simply click on the button in the top right corner with two overlapping circles to access it or navigate to View/Assistant Editor/Show Assistant editor ( ⌥⌘^↩ ).


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


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)
        }
    }
}