在下面的代码中,我试图弄清楚如何savePhoto使用SwiftUI按钮执行该功能。这实际上是我试图解决的问题的简化版本,但仍然无法弄清楚。我在 中创建的按钮ContentView是我想象中解决问题的方式,但由于 SwiftUI 结构,我似乎无法找到解决方法。
这是我的 SwiftUI 视图:
struct ContentView: View {
var body: some View {
ZStack{
AnotherControllerView()
Button(action: { AnotherControllerView.savePhoto() }){
Text("Save Photo")
}
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
Run Code Online (Sandbox Code Playgroud)
还有我集成的 UIViewController:
import Foundation
import SwiftUI
import UIKit
struct AnotherControllerView : UIViewControllerRepresentable {
typealias UIViewControllerType = AnotherController
func makeCoordinator() -> AnotherControllerView.Coordinator {
Coordinator(self)
}
func makeUIViewController(context: UIViewControllerRepresentableContext<AnotherControllerView>) -> AnotherController {
return AnotherController() …Run Code Online (Sandbox Code Playgroud)