Disabling an Orientation Mode
Copy struct UserView : View {
var body: some View {
Group {
Text ( "Name: Paul" )
Text ( "Country: England" )
Text ( "Pets: Luna and Arya" )
}
. font ( .title )
}
}
struct ContentView : View {
@State private var layoutVertically = false
var body: some View {
Group {
if layoutVertically {
VStack {
UserView ()
}
} else {
HStack {
UserView ()
}
}
}
. onTapGesture {
layoutVertically. toggle ()
}
}
}
Transition between Layout Modes Automatically (VStack / HStack)
This code looks at the space needed and then changes the layout. It also depends on the screen size you use.
Copy struct UserView : View {
var body: some View {
Group {
Text ( "Name: Paul" )
Text ( "Country: England" )
Text ( "Pets: Luna and Arya" )
}
. font ( .title )
}
}
struct ContentView : View {
@Environment ( \.horizontalSizeClass ) var sizeClass
var body: some View {
if sizeClass == .compact {
VStack {
UserView ()
}
} else {
HStack {
UserView ()
}
}
}
}
Copy struct UserView : View {
var body: some View {
Group {
Text ( "Name: Paul" )
Text ( "Country: England" )
Text ( "Pets: Luna and Arya" )
}
. font ( .title )
}
}
struct ContentView : View {
@Environment ( \.horizontalSizeClass ) var sizeClass
var body: some View {
if sizeClass == .compact {
VStack ( content : UserView. init )
} else {
HStack ( content : UserView. init )
}
}
Making NavigationView work in Landscape (on iPhone)
Ne kadar yerinin olduğuna bakıyor. Yeteri kadar yerin var mı? Yoksa yok mu? Buna göre harekete geçebiliyorsun. Örneğin ekrandaki imgelerin ebatlarını değiştirebiliyorsun.
@Environment (.verticalsizeClass) var verticalsizeClass @Environment (.horizontalSizeClass) var horizontalSizeClass
Changing a view’s layout in response to size classes