SwiftUI - PresentationButton with modal that is full screen

后端 未结 6 2089
滥情空心
滥情空心 2020-12-08 10:18

I am trying to implement a button that presents another scene with a \"Slide from Botton\" animation.

PresentationButton looked like a good candidate, so I gave it

6条回答
  •  臣服心动
    2020-12-08 10:44

    Unfortunately, as of Beta 2 Beta 3, this is not possible in pure SwiftUI. You can see that Modal has no parameters for anything like UIModalPresentationStyle.fullScreen. Likewise for PresentationButton.

    I suggest filing a radar.

    The nearest you can currently do is something like:

        @State var showModal: Bool = false
        var body: some View {
            NavigationView {
                Button(action: {
                    self.showModal = true
                }) {
                    Text("Tap me!")
                }
            }
            .navigationBarTitle(Text("Navigation!"))
            .overlay(self.showModal ? Color.green : nil)
        }
    

    Of course, from there you can add whatever transition you like in the overlay.

提交回复
热议问题