【问题标题】:Switching from a SpriteKit scene to an UIView in Swift在 Swift 中从 SpriteKit 场景切换到 UIView
【发布时间】:2015-02-26 20:49:38
【问题描述】:

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

【问题讨论】:

    标签: swift


    【解决方案1】:

    如果您只想显示一个弹出菜单,您可以访问您的 SKScene 视图并将您的 UIView 添加为子视图:

    self.view?.addSubview(yourView)
    

    或者,如果您想移动到另一个 UIViewcontroller,您可以访问您的视图的 rootViewController 并从那里展示您的视图控制器:

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

    【讨论】:

    • 它可以工作,但我收到一个问题,显示不受支持的配置,指出由于缺少入口点,场景无法访问。我没有入口点,因为输入的唯一方法是通过代码,当你输了(没有按钮)。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-21
    • 2015-01-25
    • 1970-01-01
    • 2015-11-16
    • 2023-04-03
    • 1970-01-01
    相关资源
    最近更新 更多