How can I place a SpriteKit AdBanner at the Top of the View?

只谈情不闲聊 提交于 2019-12-08 11:34:57

问题


How can i place an iAd Banner at the Top of the View in a SpriteKit Application?

The Banner is working perfectly but on the wrong position.

Here is the code for the iAd Banner, but the its always below:

ViewController.m

- (void)viewDidLoad
{
    [super viewDidLoad];

    // Configure the view.
    SKView * skView = (SKView *)self.originalContentView;
    skView.showsFPS = YES;
    skView.showsNodeCount = YES;

    // Create and configure the scene.
    SKScene * scene = [MyScene sceneWithSize:skView.bounds.size];
    scene.scaleMode = SKSceneScaleModeAspectFill;

    self.canDisplayBannerAds = YES;

    // Present the scene.
    [skView presentScene:scene];

}

回答1:


I can't tell from the code you posted how much you have implemented already, so for completeness...

Import iAd

@import iAd;

My preference has been to just create the ADBannerView class variable as a private instance iVar.

@implementation ViewController {
    ADBannerView *_bannerView;
}

Then in viewDidLoad

-(void)viewDidLoad {
    // iAd support
    _bannerView = [[ADBannerView alloc] initWithAdType:ADAdTypeBanner];
    _bannerView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
    _bannerView.delegate = self;
    [self.view addSubview:_bannerView];
}

For an iAd banner that displays across the top of the screen, this has been all that is required to get it to show up on screen.

For the delegate methods, my current strategy is to hide the banner when it doesn't have anything to display.

#pragma mark - iAd Methods
- (void)bannerViewDidLoadAd:(ADBannerView *)banner {
    _bannerView.hidden = NO;
}

- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error {
    _bannerView.hidden = YES;
}

- (BOOL)bannerViewActionShouldBegin:(ADBannerView *)banner willLeaveApplication:(BOOL)willLeave {
    return YES;
}

- (void)bannerViewActionDidFinish:(ADBannerView *)banner {
}


来源:https://stackoverflow.com/questions/23414095/how-can-i-place-a-spritekit-adbanner-at-the-top-of-the-view

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!