当我向ViewController添加iAd横幅时,SKScene被调用两次

时间:2014-11-07 00:40:58

标签: ios sprite-kit iad

当我在viewcontroller中有一个iad横幅时,我发现我的主菜单场景被调用了两次。有谁知道为什么这样做?

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


    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:1];
    [banner setAlpha:1];
    [UIView commitAnimations];



}

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

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
[banner setAlpha:0];
[UIView commitAnimations];

}
在viewcontroller.h中

@interface GameViewController : UIViewController <ADBannerViewDelegate>{

我认为他们可能是UIView的问题,因为我听说UIViews与Sprite-Kit不兼容

1 个答案:

答案 0 :(得分:0)

我不确定这可能是这项工作。

ViewController.m

- (void)viewWillLayoutSubviews
{
    [super viewWillLayoutSubviews];

    [banner setAlpha:0];

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleNotification:) name:@"hideAd" object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleNotification:) name:@"showAd" object:nil];
}


- (void)handleNotification:(NSNotification *)notification
{
    if ([notification.name isEqualToString:@"hideAd"]) {
        [banner setAlpha:0];
    }else if ([notification.name isEqualToString:@"showAd"]) {
        [banner setAlpha:1];
    }
}

在你想要的场景中用这个来打电话

[[NSNotificationCenter defaultCenter] postNotificationName:@"showAd" object:nil];