在ios8中使用appdelegate暂停spritekit游戏

我在我的游戏中有一个暂停菜单,当我点击主页button时,我想要切换。 当我在我的游戏中时,它是有效的,但是当我点击主页button时,菜单出现了,但游戏不会暂停。

当我重新启动应用程序时,菜单仍然存在,但是游戏不会暂停。 看起来像spritekit会自动暂停并重新启动游戏,当你离开并进入应用程序。 当我在应用程序内,我完全控制它。 但是当我退出/进入应用程序时,它的行为如何。

有什么build议么?

func applicationWillResignActive(application: UIApplication!) { // get the root viewcontroller // toggle my pausemenu method. pause menu sets skview.paused = true } 

发送一个NSNotificationGameSceneViewController来暂停SKScene

AppDelegate中:

 - (void)applicationWillResignActive:(UIApplication *)application { // Pause sprite kit scene [[NSNotificationCenter defaultCenter] postNotificationName:@"PauseGameScene" object:self]; } 

GameSceneViewController:

 - (void)viewDidLoad { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pauseGameScene) name:@"PauseGameScene" object:nil]; } - (void)pauseGameScene { if (self.skView.scene) { self.skView.paused = self.skView.scene.paused = YES; } }