在iPad上显示的模态视图上不需要的SplitView [英] Unwanted SplitView on modal view displayed on iPad

查看:47
本文介绍了在iPad上显示的模态视图上不需要的SplitView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在iPad上测试我的第一个SwiftUI应用程序后,我发现从ContentView中显示的模式视图在iPad上显示为拆分"视图,UI在主端被截断,详细信息侧为空.

我确实在这里检查了两个帖子:

以下是模态中我NavigationView的结尾:

 }//VStack结束.navigationBarItems(领导:按钮(完成"){self.saveEdits()self.presentationMode.wrappedValue.dismiss()//关闭视图}//按钮完成"的结束).navigationBarTitle(起飞版")}//导航视图的结尾.navigationViewStyle(StackNavigationViewStyle).onAppear {//分配了获取的事件日期,此处可用(不在init()中)self.selectedDate = self.fetchedEvent.first?.eventDate?日期()}}//某些视图的结尾 

我想发布的解决方案是从ContentView NavigationView应用该修饰符,但是我没有修饰符(并且由于在UI上丢失了所有屏幕空间而不想使用修饰符)

解决方案

此处已解决(必须进行构造,即 StackNavigationViewStyle()):

 }//导航视图的END.navigationViewStyle(StackNavigationViewStyle())//<<这里 !! 

Testing my first SwiftUI app on iPad, I discovered that the modal views I display from my ContentView are displayed as Split views on the iPad, with the UI being truncated on the master side and the detail side is empty.

I did check both posts here :

Unwanted SplitView and, What's the equality of the UISplitView controller

But their solution of applying the .navigationViewStyle(StackNavigationViewStyle) to the NavigationView does not work for me :

I display my modals through user input (tap of a button) using the following method :
When a button is pressed, an Int value is passed to a local var (modalViewCaller) and then to the sheetContent() function.
Here is the end of my var body: some View and the following 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

Then in each of these modalViews, I apply the .navigationViewStyle(StackNavigationViewStyle) modifier to the NavigationView that encapsulate my entire view in var body: some View, but I get the following error : "Type 'StackNavigationViewStyle.Type' cannot conform to 'NavigationViewStyle'; only struct/enum/class types can conform to protocols"

Here is the end of my NavigationView in the modals :

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

I guess the solution posted was to apply that modifier from the ContentView NavigationView, but I don't have one (and don't want one because of all the screen real estate lost on top of my UI)

解决方案

Here is fix (it has to be constructed, ie. StackNavigationViewStyle()):

} // END of Navigation View
.navigationViewStyle(StackNavigationViewStyle()) // << here !! 

这篇关于在iPad上显示的模态视图上不需要的SplitView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆