【发布时间】:2020-08-27 09:59:18
【问题描述】:
出乎意料的是,SwiftUI 的推送视图会在过渡时临时渲染其内容,并为隐藏的导航栏留出空间。片刻之后,它重新正确渲染。如何防止这种行为?
对于 GIF 屏幕录制,请单击下面的图像。
ContentView.swift
import SwiftUI
struct ContentView: View {
@State var goToNextView = false
var body: some View {
NavigationView { ZStack {
/*@START_MENU_TOKEN@*/Color.yellow/*@END_MENU_TOKEN@*/.edgesIgnoringSafeArea(.all)
NavigationLink(destination: SecondView(), isActive: $goToNextView) {Text("")}
.navigationBarTitle("")
.navigationBarHidden(true)
.navigationBarBackButtonHidden(true)
VStack {
Button(action: {
print("Button clicked")
self.goToNextView = true
}) { Text("Go to second view") }
.padding()
Text("This is the first view.")
}
}
.foregroundColor(Color.blue)
}
}
}
SecondView.swift
struct SecondView: View {
var body: some View {
ZStack {
Color.purple
.edgesIgnoringSafeArea(.all)
.navigationBarBackButtonHidden(true)
.navigationBarHidden(true)
VStack { Text("Pushed view") }
}
.foregroundColor(Color.white)
}
}
【问题讨论】:
标签: swiftui swiftui-navigationlink