SwiftUI: unwanted split view on iPad
Update July 2022
Using NavigationStack
instead of NavigationView
should display as the main view as you would expect on iPad:
NavigationStack {
Text("Hello world!")
}
*In newer versions, the navigationViewStyle
modifier has been deprecated.
Original answer:
You can apply the .navigationViewStyle(.stack)
modifier to the NavigationView.
...
NavigationView {
Text("Hello world!")
}
.navigationViewStyle(.stack)
...
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
Disable split view using Swift UI on iPad
By setting the NavigationViewStyle
import SwiftUI
struct NavView: View {
var body: some View {
NavigationView{
List{
NavigationLink(destination: TestView(), label: {Text("TestView")})
}
}.navigationViewStyle(StackNavigationViewStyle())
}
}
struct NavView_Previews: PreviewProvider {
static var previews: some View {
NavView()
}
}
Unwanted SplitView on modal view displayed on iPad
Here is fix (it has to be constructed, ie. StackNavigationViewStyle()
):
} // END of Navigation View
.navigationViewStyle(StackNavigationViewStyle()) // << here !!
NavigationView SwiftUI shows split view in iPad
Use stack navigation view style explicitly (by default it is platform-dependent)
NavigationView {
Text("Hello")
.navigationBarTitle("Home")
}
.navigationViewStyle(StackNavigationViewStyle())
How to show same view as iPhone on iPad instead of Split view?
Hard to say without any code, but I bet you need to add .navigationViewStyle(StackNavigationViewStyle())
to your NavigationView to not get it in split view mode on the iPad:
NavigationView {
View1()
}.navigationViewStyle(StackNavigationViewStyle())
How to change master view width in SwiftUI split view on iPad
To change the default width of the master view you may install SwiftUI-Introspect and add this to your NavigationView:
.introspectNavigationController { navigationController in
navigationController.splitViewController?.preferredPrimaryColumnWidthFraction = 1
navigationController.splitViewController?.maximumPrimaryColumnWidth = *preferred width*
}
Related Topics
How to Create a Glow Around a Sprite via Skeffectnode
Read a Text File Line by Line in Swift
Change Uidatepicker Font Color
iOS Provisioning and Certifcates - Will Revoke/Renew Effect App Store Apps
Re-Authenticating User Credentials Swift
Allowing Single Digit in Uitextfield in iOS
How to Embed a Uitableview in a Uiscrollview
How to Fill a Bezier Path with Gradient Color
Ionic 2, Using Angular 2 Pipe Breaks on iOS-"Can't Find Variable: Intl"
How to Calculate the Age Based on Nsdate
New Foursquare Venue Detail Map
How to Disable Caching from Nsurlsessiontask
How to Select Range of Values When Using Arc4Random()
Swift - Coredata Migration - Set New Attribute Value According to Old Attribute Value