SwiftUI - 具有全屏模式的 PresentationButton [英] SwiftUI - PresentationButton with modal that is full screen

查看:25
本文介绍了SwiftUI - 具有全屏模式的 PresentationButton的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试实现一个按钮,该按钮使用从底部滑动"动画呈现另一个场景.

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

PresentationButton 看起来不错,所以我试了一下:

PresentationButton looked like a good candidate, so I gave it a try:

import SwiftUI

struct ContentView : View {
    var body: some View {
        NavigationView {
            PresentationButton(destination: Green().frame(width: 1000.0)) {
                Text("Click")

                }.navigationBarTitle(Text("Navigation"))
        }
    }
}

#if DEBUG
struct ContentView_Previews : PreviewProvider {
    static var previews: some View {
        Group {
            ContentView()
                .previewDevice("iPhone X")
                .colorScheme(.dark)

            ContentView()
                .colorScheme(.dark)
                .previewDevice("iPad Pro (12.9-inch) (3rd generation)"

            )

        }

    }
}
#endif

结果如下:

我希望绿色视图覆盖整个屏幕,并且模态不能拖动关闭".

I want the green view to cover the whole screen, and also the modal to be not "draggable to close".

是否可以为 PresentationButton 添加修饰符以使其全屏显示且不可拖动?

Is it possible to add modifier to PresentationButton to make it full screen, and not draggable?

我也尝试过导航按钮,但是:- 它不会从底部滑动"- 它在详细视图上创建了一个后退按钮",我不想要

I have also tried a Navigation Button, but: - It doesn't "slide from bottom" - It creates a "back button" on detail view, which I don't want

谢谢!

推荐答案

不幸的是,从 Beta 2 Beta 3 开始,这在纯 SwiftUI 中是不可能的.您可以看到 Modal 没有任何参数,例如 <代码>UIModalPresentationStyle.fullScreen.PresentationButton 也是如此.

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.

我建议提交雷达.

您目前可以做的最近的事情是:

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.

这篇关于SwiftUI - 具有全屏模式的 PresentationButton的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆