【问题标题】:Value of type 'GameScene' has no member 'presentViewController' in Swift“GameScene”类型的值在 Swift 中没有成员“presentViewController”
【发布时间】:2016-04-06 14:24:52
【问题描述】:

我正在尝试展示一个菜单(GameViewController)。我尝试在 GameScene 中执行此动作:

let secondViewController:GameViewController = GameViewController()

self.presentViewController(secondViewController, animated: true, completion: nil)

但是self.presentViewController(secondViewController, animated: true, completion: nil) 行有一个错误,它显示“'GameScene' 类型的值在 Swift 中没有成员 'presentViewController'”。我无法使用 .presentViewController 执行移动,它需要以编程方式完成且不使用 segue,并且它必须能够在 SKScene 中使用。

提前致谢, 尼尔

【问题讨论】:

  • 您需要从UIViewController 致电presentViewControllerGameScene 不是视图控制器。
  • @rmaddy 是的,但我怎么称呼它?
  • @rmaddy 我得到一个打印输出尝试在 上显示 其视图不在窗口层次结构中!当我尝试这个时:让 secondViewController:GameViewController = GameViewController() var viewh = UIViewController() viewh.presentViewController(secondViewController, animated: true, completion: nil)
  • 您必须获得对已显示的现有视图控制器的引用。您不能只创建一个新的并从中呈现。
  • @rmaddy 我应该如何在代码中引用它?

标签: ios swift skscene


【解决方案1】:

根据 Apple 的说法,游戏中的每个不同场景或屏幕都应该呈现不同的 SKScene 对象。

单个GameViewContoller 和单个SKView 可用于呈现许多不同的场景,例如主菜单和游戏中的关卡。

例如,从 SKScene 类内部使用 self.view 引用 SKView 并告诉它显示您的主菜单 SKScene

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-09-18
    • 1970-01-01
    • 1970-01-01
    • 2019-02-14
    • 2018-11-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多