简体   繁体   English

如何阻止Sprite Kit使用iAd标语重新初始化场景

[英]How to stop Sprite Kit from reinitializing the scene with iAd banner

I made a game using sprite kit in landscape mode. 我在横向模式下使用精灵套件制作了一个游戏。 The only allowed orientations are landscape left and landscape right. 唯一允许的方向是左横向和右横向。 When I select the banner ad in my game, rather than freezing the scene and returning to the original point in the game, the entire scene reinitializes itself (music player restarts, content shows as start screen, etc). 当我在游戏中选择横幅广告时,而不是冻结场景并返回游戏中的原始点,整个场景会自行重新初始化(音乐播放器重新启动,内容显示为开始屏幕等)。

The same thing happens when I flip the phone around so that the orientation switches. 当我翻转手机以切换方向时,也会发生同样的事情。 How can I prevent this? 我该如何预防?

As for when you flip your phone you need this... 至于当您翻转手机时,您需要这个...

- (void)viewWillLayoutSubviews { 

[super viewWillLayoutSubviews];
SKView * skView = (SKView *)self.view;

if ( !skView.scene ) {...

    SKScene * scene = [MenuScene sceneWithSize:skView.bounds.size];
    scene.scaleMode = SKSceneScaleModeAspectFill;

    [skView presentScene:scene]; 
    } 
}

I'm still looking into the iAd issue, I'll update if I figure anything out. 我仍在调查iAd问题,如果发现任何问题,我会进行更新。

Thanks for the response. 感谢您的回复。 That was the problem. 那就是问题所在。 I had been initializing the scene in the viewWillLayoutSubviews method in my root view controller. 我一直在根视图控制器的viewWillLayoutSubviews方法中初始化场景。 I moved the scene initialization to the viewDidLoad method and it fixed the issue. 我将场景初始化移至viewDidLoad方法,并解决了该问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM