ios - Xcode Beta 6 中的 SwiftUI 模式?
问题描述
以前在 SwiftUI (Xcode Beta 5) 中,模态的工作方式如下:
struct ContentView: View {
@State var modalIsPresented: Bool = false
var body: some View {
Button(action: {
self.modalIsPresented = true
}) {
Text("Show modal")
}
.sheet(isPresented: $modalIsPresented, content: {
ModalView()
})
}
}
struct ModalView: View {
@Environment(\.presentationMode) var presentationMode
var body: some View {
Button(action: {
self.presentationMode.value.dismiss()
}) {
Text("Hide modal")
}
}
}
但是现在在 Xcode Beta 6 中,我找不到关闭模式的方法。不再有 的value
属性presentationMode
,其他属性似乎也没有我可以使用的有用方法。
如何在 Xcode Beta 6 中关闭 SwiftUI 模式?
解决方案
在 Xcode Beta 6 中使用WrappedValue而不是value似乎可以工作:
self.presentationMode.wrappedValue.dismiss()
推荐阅读
- android - Android Fragment 中的膨胀布局
- ios - 如何使用带有布尔值的用户默认值来检查函数是否已运行?
- azure - 在 Azure 应用服务中导出证书
- regex - 用于 URL 的 GTM 正则表达式仅向下 3 层
- php - 如何修复警告:使用 foreach 循环打印数组上的所有数据时出现非法字符串偏移“code_class”?
- azure - PDF 未通过 SAS 令牌显示
- magento - XAMPP localhost 和 Magento 2 中的 mod_rewrite
- python - 以 2D 特征数组为输入的高斯过程 - scikit-learn
- python - CPLEX 与 Python API - 如何使模型制定更快?
- javascript - 是否有理由保留 express 变量