[英]SwiftUI : view is pushed multiple times in split screen on iPad
In my app using SwiftUI, when I want to implement split view into my app, everything works well on iPhone and even on iPad unless I go to split screen mode when using multiple apps.在我使用 SwiftUI 的应用程序中,当我想在我的应用程序中实现拆分视图时,一切都在 iPhone 甚至 iPad 上运行良好,除非我在使用多个应用程序时进入分屏模式。 Here is the code : of ContentView(), if you need more don't hesitate to ask.这是 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>) {
}
}
GIF to show you the bug向您展示错误的 GIF
Thanks a lot in advance for your help.非常感谢您的帮助。
I got your code sample down to this to reproduce the bug, and it seems it's the "listStyle(GroupedListStyle())" that is causing it.我将您的代码示例归结为这个以重现该错误,似乎是“listStyle(GroupedListStyle())”造成的。 Removing that and the bug goes away.删除它,错误就会消失。
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
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.