ios - SwiftUI:在 iPad 的分屏中多次推送视图
问题描述
在我使用 SwiftUI 的应用程序中,当我想在我的应用程序中实现拆分视图时,一切都在 iPhone 甚至 iPad 上运行良好,除非我在使用多个应用程序时进入分屏模式。这是 ContentView() 的代码,如果您需要更多,请随时询问。
import SwiftUI
import GoogleMobileAds
struct ContentView: View {
@State var isAboutViewPresented = false
var body: some View {
NavigationView {
DefaultView()
NewView()
}//.navigationViewStyle(StackNavigationViewStyle())
// To get "full screen" on iPad -> not in a split view style
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
.environment(\.locale, .init(identifier: "fr"))
}
}
struct DefaultView: View {
@State var isAboutViewPresented = false
var body: some View {
VStack {
List {
Section(header: Text("main"), footer: Text("showChartOfDesiredParameter")) {
NavigationLink(destination: ApertureStopChartView()) {
Text("apertureStopChart")
}
NavigationLink(destination: ShutterSpeedStopChartView()) {
Text("shutterSpeedStopChart")
}
NavigationLink(destination: ISOStopChartView()) {
Text("isoStopChart")
}
}
Section(header: Text("moreInfo")) {
NavigationLink(destination: WhatIsStopView()) {
Text("whatIsAStopInPhotography")
}
}
}.listStyle(GroupedListStyle())
VStack {
AdView().frame(width: 320, height: 50)
}.edgesIgnoringSafeArea([.top, .leading, .trailing])
}
.navigationBarTitle(Text("Stop Chart"))
.navigationBarItems(trailing:
Button(action: {
self.isAboutViewPresented = true
}) {Image(systemName: "info.circle")
.font(.title)
.foregroundColor(.blue)
}.sheet(isPresented: $isAboutViewPresented, content: { AboutView(onDismiss: {
self.isAboutViewPresented = false
})
})
)
}
}
struct NewView: View {
var body: some View {
VStack {
Image("StopChart-icon@1024px")
.resizable()
.frame(width: 400, height: 400, alignment: .center)
.cornerRadius(23)
HStack {
Text("swipeToTheRight").font(.largeTitle)
Image(systemName: "arrow.right").font(.largeTitle)
}
}
}
}
struct AdView: UIViewRepresentable {
func makeUIView(context: UIViewRepresentableContext<AdView>) -> GADBannerView {
let banner = GADBannerView(adSize: kGADAdSizeBanner)
banner.adUnitID = "ca-app-pub-3940256099942544/2934735716"
banner.rootViewController = UIApplication.shared.windows.first?.rootViewController
banner.load(GADRequest())
return banner
}
func updateUIView(_ uiView: GADBannerView, context: UIViewRepresentableContext<AdView>) {
}
}
非常感谢您的帮助。
解决方案
我得到了你的代码示例来重现这个错误,它似乎是导致它的“listStyle(GroupedListStyle())”。删除它,错误就消失了。
import SwiftUI
struct ContentView: View {
var body: some View {
NavigationView {
DefaultView()
}
}
}
struct DefaultView: View {
@State var isAboutViewPresented = false
var body: some View {
VStack {
List {
NavigationLink(destination: Text("TEST1")) {
Text("TEST1")
}
}
.listStyle(GroupedListStyle()) // <-- causing bug
}
}
}
推荐阅读
- java - 为什么我的 jGRASP 项目文件如此臃肿?
- google-contacts-api - 无法验证谷歌 api
- kubernetes - kuberntes/manifest 更新后 kubelet 不会启动
- php - Href 不会切换到链接的 div 标签
- ios - Siri 扩展文件在嵌入内容中被删除
- database - 用于更新对象标签的最佳 api 调用
- wordpress - 用于显示 OBJ 或 FBX 3D 对象的 Wordpress 插件
- python - 在 python3.7 中安装 pytorch 的问题
- android - 打开失败:EACCES(权限被拒绝)ANDROID 11
- c++ - clang/clang-cl 未定义符号“__tls_index”(自定义 CRT 实现)