SpriteKit - how to correctly pause and resume app

主宰稳场 提交于 2019-11-29 06:58:57

You could subscribe to these notifications yourself within the ViewController that manages the SKView. Then you don't have to navigate some weird hierarchy to obtain it.

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(willEnterBackground)
                                             name:UIApplicationDidEnterBackgroundNotification
                                           object:nil];

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(willEnterForeground)
                                             name:UIApplicationWillEnterForegroundNotification
                                           object:nil];

- (void)willEnterForeground {
    self.skView.paused = NO;
}

- (void)willEnterBackground {
    // pause it and remember to resume the animation when we enter the foreground
    self.skView.paused = YES;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!