主页按钮按下会导致SpriteKit SKView中的EXC_BAD_ACCESS代码= 1 [英] Home button press causes EXC_BAD_ACCESS code=1 in SpriteKit SKView

查看:155
本文介绍了主页按钮按下会导致SpriteKit SKView中的EXC_BAD_ACCESS代码= 1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

SpriteKit is supposed to clean up and pause all timers when you press the home button.

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

However, we have found that if you single tap the home button while displaying an active SKView, the app crashes. This occurs even if that view is already paused by the user.

奇怪的是,如果您双击主页按钮并转到多任务处理视图,一切正常。

Strangely, if you double tap the home button and move to the multitasking view, everything works fine.

跟进注意:模拟器在两种情况下都能正常运行,不会崩溃

Follow Up Note: The simulator works perfectly in both situations, no crash

是其他人用SpriteKit看到这个问题?

Is anyone else seeing this issue with SpriteKit?

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

Have you found the cause / solution?

推荐答案

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

I was having the same problem and I solved it manually pausing the root SKView in the ViewController before the app moving to the background:

- (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];
}

这篇关于主页按钮按下会导致SpriteKit SKView中的EXC_BAD_ACCESS代码= 1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆