問題:如何從我的GameScene.swift中關閉ViewController?如何從我的GameScene.swift中關閉ViewController?
SITUTATION:我有2個風投在我的SpriteKit遊戲,像這樣:
ViewController.swift ----按播放-----> GameViewController
當玩家失去了,我想解散GameViewController,這樣玩家可以再次按下游戲。我在GameScene.swift中檢查玩家的損失,並想從那裏解散GameVC。
N.B:沒有成功Google搜索這一點。
我的嘗試:
1)創建我的GameScene.swift一個gameVC實例,並駁回它像這樣:
let gameVC = GameViewController()
gameVC.dismissViewController(false,completion: nil)
2)這樣做:
self.view.window!.rootViewController?.dismissViewControllerAnimated(false, completion: nil)
那些不原因是顯而易見的^^工作
1)不起作用:您需要使用* existing *實例,而不是新的實例。 2)只有在'self.view.window!.rootViewController?'是你的'GameViewController'實例時纔會起作用,但它看起來可能是'ViewController'。 –
@AaronBrager是的,我知道:)這就是爲什麼我把它放在「我試過」部分。我只是看不到如何抓住現有的實例:/ – Coder1000
您需要將'GameScene'作爲視圖控制器的引用,以便它可以關閉它,或者使用委託模式向後通信到控制對象,即VC應該被解僱/自行解僱 –