我已经访问过这个答案,这里提出的present
方法不起作用(不再?)。当我使用 aUIViewControllerRepresentable
然后将其显示为工作表时,它看起来非常糟糕:
如果我使用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
} …
Run Code Online (Sandbox Code Playgroud)