按下主页按钮时暂停 Sprite Kit 场景 [英] Pause Sprite Kit scene when home button is pressed
问题描述
我想知道当按下主页按钮时如何暂停我的精灵套件场景.
I was wondering how would i pause my sprite kit scene when home button is pressed.
我在这里找到的答案很少,并尝试使用这样的通知中心.
I found few answers here and tried it with notification center like this.
当我的场景加载时:
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(applicationDidEnterBackground)
name:UIApplicationDidEnterBackgroundNotification
object:nil];
然后是进入后台调用的方法:
And then later the method that is called if enters to background:
- (void) applicationDidEnterBackground{
NSLog(@"Enter to background");
self.scene.view.paused =YES;
}
这里的问题是我收到了 NSLog 消息,因此正确调用了 applicationDidEnterBackground 方法.但问题是当我返回应用程序时,我的应用程序未处于暂停"模式.
Problem here is that i get the NSLog message so applicationDidEnterBackground method is being called properly. But problem is that when I return to application my app is not on "pause" mode.
所以我的暂停语句 (self.scene.view.paused =YES;) 没有被调用?
So my pause statement (self.scene.view.paused =YES;) is not being called?
如果我将确切的语句放在代码中的其他地方,或者如果我用这个语句创建一个暂停按钮 pause 就可以了.
If I put exact statement somewhere else in code or if I make a pause button with this statement pause works just fine.
有什么问题?为什么这不适用于通知中心?
What is the problem? Why this won't work with notification center?
推荐答案
iOS 8 的 Sprite kit 在退出后台模式后会自动恢复你的游戏.它发生在调用 applicationDidBecomeActive 之后.此外,iOS 8 的 Sprite 工具包会在您的游戏移至后台时自动暂停.
Sprite kit for iOS 8 automatically resumes your game after exiting background mode. It happens after applicationDidBecomeActive is called. Also, Sprite kit for iOS 8 automatically pauses your game when it moves to the background.
更新:以下是 Xcode 5 和 6 进入/退出后台模式时 skView.paused 的状态.
Update: The following are the states of skView.paused when enter/exiting background mode for Xcode 5 and 6.
Xcode 6
部署目标 7.0、7.1**、8.0 和 8.1
Deployment targets 7.0, 7.1**, 8.0, and 8.1
applicationWillResignActive = NO
applicationDidEnterBackground = YES
applicationWillEnterForeground = YES
applicationDidBecomeActive = YES
** 当我在运行 iOS 7.1 的设备上运行时,状态都是 NO
** When I ran on a device running iOS 7.1, the states were all NO
Xcode 5
部署目标 7.0 和 7.1
Deployment targets 7.0 and 7.1
applicationWillResignActive = NO
applicationDidEnterBackground = NO
applicationWillEnterForeground = NO
applicationDidBecomeActive = NO
这篇关于按下主页按钮时暂停 Sprite Kit 场景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!