如何解决从 UIViewControllerRepresentable 向 swiftui 视图发送一个事件
我尝试在 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。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。