【发布时间】:2020-09-17 11:43:51
【问题描述】:
我是 SwiftUI 的新手。我的问题是当 \user 使用 iPhone 启动应用程序时,他们只能在纵向模式下使用该应用程序。如果用户使用 iPad 启动应用程序,则应该可以在纵向和横向模式下使用该应用程序。我想我需要UIDevice.current.model,但是我该如何实现呢?
import SwiftUI
import UIKit
struct ContentView: View {
@State var value_2 = 1
@State var show_1 = false
var body: some View {
VStack {
Button(action: {
self.show_1.toggle()
}) {
Text("Push")
}
.sheet(isPresented: $show_1) {
Sheet(show_0: self.$show_1, value_1: self.$value_2)
}
}
}
}
struct Sheet: View {
@Binding var show_0: Bool
@Binding var value_1: Int
var body: some View {
NavigationView {
number(value_0: $value_1)
.navigationBarTitle(Text("Enter number"), displayMode: .inline)
.navigationBarItems(trailing: Button(action: {
self.show_0 = false
}) {
Text("Done").bold()
})
}.navigationViewStyle(StackNavigationViewStyle())
}
}
struct number: View {
@Binding var value_0: Int
var body: some View {
Section {
Text("Headline")
Picker("",selection: $value_0)
{
ForEach(1..<101) { value in
Text("\(value)")
}
}
}
.labelsHidden()
}
}
【问题讨论】: