6

当您按下主页按钮时,SpriteKit 应该会清理并暂停所有计时器。

但是,我们发现如果您在显示活动的 SKView 时单击主页按钮,应用程序会崩溃。即使该视图已被用户暂停,也会发生这种情况。

奇怪的是,如果你双击主页按钮并移动到多任务视图,一切正常。

后续注意:模拟器在两种情况下都能完美运行,没有崩溃

有没有其他人看到 SpriteKit 的这个问题?

您找到原因/解决方案了吗?

4

4 回答 4

10

我遇到了同样的问题,我在应用程序移动到后台之前手动暂停了 ViewController 中的根 SKView 解决了它:

- (void)viewDidLoad
{
    [super viewDidLoad];

    // Configure the view (already setup as SKView via storyboard)
    SKView * skView = (SKView *)self.view; 

    // Create and configure the scene.
    SKScene *scene = [Menu sceneWithSize:CGSizeMake(skView.bounds.size.height, skView.bounds.size.width)];
    scene.scaleMode = SKSceneScaleModeAspectFill;

    // Present the scene.
    [skView presentScene:scene];
    [[NSNotificationCenter defaultCenter]
    addObserver:self
    selector:@selector(appWillEnterBackground)
    name:UIApplicationWillResignActiveNotification
    object:NULL];
}

- (void)appWillEnterBackground
{
    SKView *skView = (SKView *)self.view;
    skView.paused = YES;
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    [[NSNotificationCenter defaultCenter]
    addObserver:self
    selector:@selector(appWillEnterForeground)
    name:UIApplicationWillEnterForegroundNotification
    object:NULL];
}

- (void)appWillEnterForeground
{
    SKView * skView = (SKView *)self.view;
    skView.paused = NO;
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    [[NSNotificationCenter defaultCenter]
    addObserver:self
    selector:@selector(appWillEnterBackground)
    name:UIApplicationWillResignActiveNotification
    object:NULL];
}
于 2014-01-06T02:30:55.437 回答
0
  1. 运行 Xcode 的分析器(项目 > 分析)以确定代码中是否存在内存管理问题。

  2. 在 Instruments 应用程序(Project > Profile)的分配工具中运行这个场景,它可以报告任何检测到的内存滥用。

于 2013-09-27T20:14:52.440 回答
0

我们在使用 UICollectionView 时遇到了一些类似的不一致行为。在这种情况下,通过情节提要(相对于以编程方式)实例化对象解决了该问题。

凭直觉,我今天早上尝试了 Viola,成功了!

因此,Storyboards 似乎在创建我们不知道的 SKView 时发挥了一些魔力,并允许它们在按下 Home 按钮时正确终止。令人沮丧,但至少它现在有效。

于 2013-11-05T15:32:14.663 回答
0

问题可能是由音频引起的,如果是这样,您可以在此处查看答案https://stackoverflow.com/a/19283721/1278463

我在不使用音频的游戏中解决了这个问题。解决方案是在进入后台时暂停 SKView:

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    SKView *view = (SKView *)self.window.rootViewController.view;
    if (view) {
        view.paused = YES;
    }
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    SKView *view = (SKView *)self.window.rootViewController.view;
    if (view) {
        view.paused = NO;
    }
}
于 2014-06-19T15:18:14.353 回答