Skip to main content
 首页 » 操作系统

swift之从 SpriteKit 场景切换到 Swift 中的 UIView

2024年01月01日35itcoder

我正在开发 Swift SpriteKit 游戏,我需要一点帮助。我有游戏运行的游戏场景,当玩家死亡时我想加载另一个带有按钮和标签的场景以获得分数,但我希望这个场景是 UIView 而不是 SpriteKit 场景。如何从 SpriteKit 场景加载 UIView?适用于当前场景?非常感谢!

请您参考如下方法:

如果你只想显示一个弹出菜单,你可以访问你的 SKScene View 并将你的 UIView 添加为 subview :

self.view?.addSubview(yourView) 

或者,如果您想移动到另一个 UIViewcontroller,您可以访问 View 的 rootViewController 并从那里显示您的 View Controller :

self.view?.window?.rootViewController?.presentViewController(viewControllerToPresent: YourViewController, animated: true, completion: nil)