首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在使用GKGameCenterViewController UIViewControlllerRepresentable时不能排除SwiftUI

在使用GKGameCenterViewController UIViewControlllerRepresentable时不能排除SwiftUI
EN

Stack Overflow用户
提问于 2022-02-04 16:25:26
回答 1查看 91关注 0票数 0

我有一个使用UIViewControllerRepresentable实现GKGameCenterViewController的SwiftUI。我已经完成了所有必要的设置与游戏中心和这个GKGameCenterViewController确实出现在我的SwiftUI视图调用。但是,我不能拒绝它。我知道需要一个Coordinator来实现GKGameCenterControllerDelegate,我已经这样做了。但它仍未驳回。我不知道我做错了什么。

代码语言:javascript
运行
复制
struct GameCenterView: UIViewControllerRepresentable {

    func makeCoordinator() -> Coordinator {
        Coordinator(self)
    }

    func updateUIViewController(_ uiViewController: GKGameCenterViewController, context: Context) {

    }

    func makeUIViewController(context: Context) -> GKGameCenterViewController {
        let vc = GKGameCenterViewController()
        vc.delegate = context.coordinator
        return vc
    }

    class Coordinator: NSObject, GKGameCenterControllerDelegate, UINavigationControllerDelegate {
        var parent: GameCenterView

        func gameCenterViewControllerDidFinish(_ gameCenterViewController: GKGameCenterViewController) {
            gameCenterViewController.dismiss(animated: true, completion: nil)
        }

        init(_ parent: GameCenterView) {
            self.parent = parent
        }
    }
}
EN

回答 1

Stack Overflow用户

发布于 2022-03-29 23:13:26

我有个办法。

delegate看上去不对。你可以用gameCenterDelegate

就像这样:

代码语言:javascript
运行
复制
vc.gameCenterDelegate = context.coordinator
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70989666

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档