【发布时间】:2019-10-30 02:36:29
【问题描述】:
在 WWDC 2019 上,Apple 宣布了一种用于模态演示的新“卡片式”外观,它带来了通过向下滑动卡片来关闭模态视图控制器的内置手势。他们还在UIViewController 上引入了新的isModalInPresentation 属性,以便您可以选择禁止这种解雇行为。
不过,到目前为止,我还没有找到在 SwiftUI 中模拟这种行为的方法。据我所知,使用.presentation(_ modal: Modal?) 不允许您以相同的方式禁用解除手势。我还尝试将模态视图控制器放在 UIViewControllerRepresentable View 中,但这似乎也没有帮助:
struct MyViewControllerView: UIViewControllerRepresentable {
func makeUIViewController(context: UIViewControllerRepresentableContext<MyViewControllerView>) -> UIHostingController<MyView> {
return UIHostingController(rootView: MyView())
}
func updateUIViewController(_ uiViewController: UIHostingController<MyView>, context: UIViewControllerRepresentableContext<MyViewControllerView>) {
uiViewController.isModalInPresentation = true
}
}
即使在使用.presentation(Modal(MyViewControllerView())) 进行演示后,我也能够向下滑动以关闭视图。目前有什么方法可以使用现有的 SwiftUI 结构来做到这一点?
【问题讨论】: