swiftui - 如何在仅 SwiftUI 的项目中正确呈现 PKPaymentAuthorizationViewController?

标签 swiftui uikit applepay passkit

我已经访问过这个答案和 the present method proposed here不起作用(不再?)。当我使用 UIViewControllerRepresentable然后将其显示为一张看起来很糟糕的表格:
Screenshot UIViewControllerRepresentable sheet
如果我使用 overlay它看起来和我想要的完全一样,但是 overlay无法从 Button 触发.
这是(浓缩的)代码:

public struct ContentView: View {
    @ObservedObject var model: RootViewModel
    @State private var tappedDonate = false

    public var body: some View {
            Button(action: {
                tappedDonate = true
            }, label: {
                Text("Donate")
                    .frame(width: 300, height: 44, alignment: .center)
            })
            .frame(width: 300, height: 20, alignment: .center)
            .padding()
            .background(Color.black)
            .foregroundColor(.white)
            .cornerRadius(22)
            .sheet(isPresented: $tappedDonate) {
                ApplePayWrapper(request: model.buildApplePayment())
                    .background(Color.clear)
            }
    }

    public init(model: RootViewModel) {
        self.model = model
    }
}

最佳答案

我不是 100% 相信这是最好的方法,但我设法让它在视觉上工作,就像我打算使用 ZStack 一样工作。 :


        ZStack {           
            Button(action: {
                tappedDonate = true
            }, label: {
                Text("Donate")
                    .frame(width: 300, height: 44, alignment: .center)
            })
            .frame(width: 300, height: 20, alignment: .center)
            .padding()
            .background(Color.black)
            .foregroundColor(.white)
            .cornerRadius(22)
            if tappedDonate {
                ApplePayWrapper(request: model.buildApplePayment())
            }
        }
请注意,您仍然需要通过委托(delegate)在外部点击来连接取消按钮以及常规关闭,否则带有按钮的底层 UI 不会再次响应触摸。

关于swiftui - 如何在仅 SwiftUI 的项目中正确呈现 PKPaymentAuthorizationViewController?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62638416/

相关文章:

ios - 如何使用 SwiftUI 获得动态 View 列表

ios - 从图像中捕获文本 - SwiftUI

javascript - 自动溢出的可变高度

ios - 删除 UIPopoverPresentationController 的左右边距?

ios - Apple Pay 应用内配置卡

ios - 苹果和 Stripe : Merchant id/apple pay certificate could not seen in xcode

ios - 如何使用 SwiftUI 在 NavigationView 中正确包含 "Add Item"按钮?

ios - 旋转时未调用 UICollectionViewDelegateFlowLayout 方法

ios - 有什么方法可以检测它何时触及 Apple Pay PKPaymentAuthorizationViewController 上的取消按钮?

swift - 使用 SwiftUI,如何使一个 Toggle 更改另一个 Toggle 的状态?