Pause Sprite Kit scene when home button is pressed

后端 未结 2 1438
北荒
北荒 2021-01-19 10:50

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.

相关标签:
2条回答
  • 2021-01-19 11:35

    By the time your application has entered the background, it's probably too late.

    Instead, we should register for the UIApplicationWillResignActiveNotification notification and handle our just-before-exit code when we receive this notification.

    0 讨论(0)
  • 2021-01-19 11:42

    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.

    Update: The following are the states of skView.paused when enter/exiting background mode for Xcode 5 and 6.

    Xcode 6

    Deployment targets 7.0, 7.1**, 8.0, and 8.1

    applicationWillResignActive = NO
    applicationDidEnterBackground = YES
    applicationWillEnterForeground = YES
    applicationDidBecomeActive = YES
    

    ** When I ran on a device running iOS 7.1, the states were all NO

    Xcode 5

    Deployment targets 7.0 and 7.1

    applicationWillResignActive = NO
    applicationDidEnterBackground = NO
    applicationWillEnterForeground = NO
    applicationDidBecomeActive = NO
    
    0 讨论(0)
提交回复
热议问题