gpt4 book ai didi

ios - 在 SpriteKit 中加载 iAd 时场景会拉伸(stretch)(横向模式)

转载 作者:行者123 更新时间:2023-11-28 20:00:09 24 4
gpt4 key购买 nike

当我尝试在 SpriteKit 中加载 iAd 时,场景会重置并重新开始,同时还会运行它已经在后台加载的场景。我创建了一个 BOOL 来帮助确定场景是否已经加载,如果已经加载,则无需再次加载。 iAd 显示正常,但场景本身在屏幕上延伸。这是我的 ViewController.m 中的代码:

@implementation ViewController
{
BOOL _sceneLoaded;
}


- (void)awakeFromNib
{
[super awakeFromNib];

[self setCanDisplayBannerAds:YES];
}

- (void)viewWillLayoutSubviews
{
[super viewWillLayoutSubviews];

SKView *skView = nil;

if (self.originalContentView) {
skView = (SKView *)self.originalContentView;
}else{
skView = (SKView *)self.view;
}

[skView setShowsDrawCount:NO];
[skView setShowsFPS:NO];
[skView setShowsNodeCount:NO];

if (_sceneLoaded == NO) {
SKScene *scene = [MainMenuScene sceneWithSize:skView.bounds.size];
[scene setScaleMode:SKSceneScaleModeFill];
[skView presentScene:scene];
_sceneLoaded = YES;
}
}

我不太确定哪里出错了。我试过在代码的不同区域调用 if (_sceneLoaded == NO) 语句,只是为了获得相同的结果。在此先感谢您的帮助。

最佳答案

下面的代码在 iOS 7 和 8 中测试并且工作正常。

在头文件中添加以下行

#import <iAd/iAd.h>

@interface GameViewController : UIViewController<ADBannerViewDelegate>{

//iAd
ADBannerView *adView;

}

在实现文件.m中添加以下代码

#import "GameViewController.h"
#import "GameScene.h"

@implementation GameViewController

-(void)viewWillLayoutSubviews{

[super viewWillLayoutSubviews];

SKView *skView;

if (self.originalContentView) {

skView = (SKView *)self.originalContentView;

}

if (!skView.scene) {

//[skView setShowsDrawCount:YES];
//[skView setShowsFPS:YES];
//[skView setShowsNodeCount:YES];

//Improve Performance
skView.ignoresSiblingOrder = YES;

GameScene *scene = [GameScene sceneWithSize:skView.bounds.size];
[scene setScaleMode:SKSceneScaleModeFill];

[skView presentScene:scene];

}

}

- (void)awakeFromNib{

[super awakeFromNib];

CGRect screenRect = [[UIScreen mainScreen] bounds];

adView = [[ADBannerView alloc] initWithFrame:CGRectZero];
adView.frame = CGRectMake(0, 0, screenRect.size.width, adView.frame.size.height);
adView.delegate=self;
[self.view addSubview:adView];
}

//iAd
-(void)bannerViewDidLoadAd:(ADBannerView *)banner {

[adView setAlpha:1.0];
NSLog(@"Show Ad");

}

-(void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error {

[adView setAlpha:0];
NSLog(@"Hide Ad");

}

//

- (BOOL)shouldAutorotate
{
return YES;
}

- (NSUInteger)supportedInterfaceOrientations
{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
return UIInterfaceOrientationMaskAllButUpsideDown;
} else {
return UIInterfaceOrientationMaskAll;
}
}

-(BOOL)prefersStatusBarHidden{

return YES;

}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}

@end

关于ios - 在 SpriteKit 中加载 iAd 时场景会拉伸(stretch)(横向模式),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24530213/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com