按下主页按钮后,我的游戏暂停。但是当我接到电话时却没有。当游戏变为活动状态时,其动作将恢复。我没有得到一个电话和按HB之间的区别。请帮帮我。
感谢。
func pauseGame(){
initResumeButton()
pause.removeFromParent()
gamePaused = true
self.paused = true
}
func resumeGame(){
resume.removeFromParent()
initPauseButton()
gamePaused = false
self.paused = false
}
func registerAppTransitionObservers(){
NSNotificationCenter.defaultCenter().addObserver(self, selector: "applicationWillResignActive", name: UIApplicationWillResignActiveNotification, object: nil)
NSNotificationCenter.defaultCenter().addObserver(self, selector: "applicationDidEnterBackground", name: UIApplicationDidEnterBackgroundNotification, object: nil)
NSNotificationCenter.defaultCenter().addObserver(self, selector: "applicationWillEnterForeground", name: UIApplicationWillEnterForegroundNotification, object: nil)
}
func applicationWillResignActive(){
if !gamePaused && state != .GameStarting{
pauseGame()
}
}
func applicationDidEnterBackground(){
self.view?.paused = true
}
func applicationWillEnterForeground(){
self.view?.paused = false
if gamePaused{
self.paused = true
}
}