【发布时间】:2023-04-02 22:15:02
【问题描述】:
在 iPad 上测试我的第一个 SwiftUI 应用程序时,我发现从 ContentView 显示的模态视图在 iPad 上显示为拆分视图,UI 在主端被截断,而细节端为空。
我确实检查了这两个帖子:
Unwanted SplitView 和, What's the equality of the UISplitView controller
但是他们将.navigationViewStyle(StackNavigationViewStyle) 应用于 NavigationView 的解决方案对我不起作用:
我使用以下方法通过用户输入(点击按钮)显示我的模式:
按下按钮时,会将 Int 值传递给本地变量 (modalViewCaller),然后传递给 sheetContent() 函数。
这是我的var body: some View 和以下sheetContent func 的结尾:
} // END of main VStack
.sheet(isPresented: $isModalPresented, content: sheetContent)
} // END of body
// modalViewCaller is the Int var I set upon button tap
@ViewBuilder func sheetContent() -> some View {
if modalViewCaller == 1 {
firstModalView()
} else if modalViewCaller == 2 {
secondModalView()
} else if modalViewCaller == 3 {
thirdModalView()
}
} // END of func sheetContent
然后在每个 modalViews 中,我将 .navigationViewStyle(StackNavigationViewStyle) 修饰符应用于将我的整个视图封装在 var body: some View 中的 NavigationView,但出现以下错误:
"类型 'StackNavigationViewStyle.Type' 不能符合 'NavigationViewStyle';只有结构/枚举/类类型可以符合协议"
这是我在模式中的 NavigationView 的结尾:
} // End of VStack
.navigationBarItems(
leading:
Button("Done") {
self.saveEdits()
self.presentationMode.wrappedValue.dismiss() // This dismisses the view
} // END of Button "Done"
)
.navigationBarTitle("Takeoff edition")
} // END of Navigation View
.navigationViewStyle(StackNavigationViewStyle)
.onAppear { // assigned fetched event date, here it is available (was not in init())
self.selectedDate = self.fetchedEvent.first?.eventDate ?? Date()
}
} // END of some View
我猜发布的解决方案是从 ContentView NavigationView 应用该修改器,但我没有(并且不想要一个,因为我的 UI 顶部的所有屏幕空间都丢失了)
【问题讨论】: