我尝试在 SwiftUI 视图中捕获 UIViewController 中发生的事件。该架构在 SwiftUI 中,在 Swift 中有一个元素:
风景
struct PlayGame: View {
var body: some View {
if stateProgress.stateOfGame == 0 {
CardsDeckRepresentable()
}
}
}
UIViewControllerRepresentable
struct CardsDeckRepresentable: UIViewControllerRepresentable {
typealias UIViewControllerType = CardsDeckViewController
func makeUIViewController(context: Context) -> CardsDeckViewController {
let deck = CardsDeckViewController()
return deck
}
func updateUIViewController(_ uiViewController: CardsDeckViewController, context: Context) {
}
}
UIViewController
class CardsDeckViewController : UIViewController, iCarouselDelegate, iCarouselDataSource{
... some code ...
func moveCardChoosen(number:Int) {
self.view.addSubview(cardMobile)
UIView.animate(withDuration: 0.5, delay: 0.0, options:[], animations: {
self.cardMobile.center.y = self.cardPlace5.center.y
}, completion: { finished in
if finished {
self.cardMobile.isHidden = true
}
})
}
}
在动画结束时,我想打电话给 swiftUIView 进行更新。
我尝试使用一些 ObservableObject 或使用 updateUIViewController 函数。我可以通过 UIViewControllerRepresentable 将数据从 SwiftUI 视图传递到 UIViewController。但是如何恢复 UIViewController 的变化呢?updateUIViewController 似乎没有被调用。