struct ModalView: View {
@State private var showDetailView = false
var body: some View {
Button {
debugPrint("模态按钮")
showDetailView.toggle()
} label: {
Text("模态跳转")
.font(.system(size: 20))
.foregroundColor(.white)
.padding(.top,10)
.padding(.bottom,10)
}
.fullScreenCover(isPresented: $showDetailView, content: {
ModalDetailView()
})
.frame(maxWidth: .infinity)
.background(.black)
.cornerRadius(10)
.padding()
}
}
struct ModalDetailView: View {
@Environment(\.presentationMode) var presentMode
var body: some View {
NavigationView {
VStack {
Text("模态视图页面")
}
.toolbar(content: {
ToolbarItem(placement: .navigationBarTrailing) {
Button {
presentMode.wrappedValue.dismiss()
} label: {
Image(systemName: "chevron.down.circle.fill")
.foregroundColor(.black)
}
}
})
}
}
}