-
Color.black.edgesIgnoringSafeArea(.all)
: 创建一个黑色背景,并扩展至安全区域外。
import SwiftUI
struct JumpView: View {
@State var showHome = false
var body: some View {
ZStack {
Color.black.edgesIgnoringSafeArea(.all)
Text("Hello")
.foregroundColor(.white)
if showHome {
Color.white.edgesIgnoringSafeArea(.all)
HomeView()
}
}
.onAppear(perform: {
DispatchQueue.main.asyncAfter(deadline: .now() + 5) {
self.showHome.toggle()
}
})
}
}
struct JumpView_Previews: PreviewProvider {
static var previews: some View {
JumpView()
}
}
.onAppear(perform:{...})
是 SwiftUI 中的一个修饰符,用于在视图出现时执行某个操作。它允许你在视图首次展示或重新出现在屏幕上时触发特定的代码块