代码之家  ›  专栏  ›  技术社区  ›  Jack Bashford

Xcode Beta 6中的SwiftUI模块?

  •  0
  • Jack Bashford  · 技术社区  · 5 年前

    以前在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

    0 回复  |  直到 5 年前
        1
  •  7
  •   szemian    5 年前

    使用 而不是 价值 似乎在Xcode Beta 6中工作:

    self.presentationMode.wrappedValue.dismiss()
    
        2
  •  4
  •   Fabian    5 年前

    .sheet , .popover .actionSheet 通过传入控制它显示的绑定,这里 $modalIsPresented 并在内部将其设置为false,以编程方式消除它。

        3
  •  2
  •   Joannes    5 年前

    .presentation(showModal ? Modal(Text("Modal screen"), onDismiss: {
    self.showModal.toggle()
    }) : nil)
    

    默认的模式显示不能证明用户关闭模式的任何视觉方式,但从iOS 13开始,用户可以向下滑动视图使其消失。

    详细内容: https://alejandromp.com/blog/2019/06/24/improving-swiftui-modal-presentation-api/