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



当我的视图控制器中有一个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的一个问题,因为我听说UIView与Sprite Kit 不太好用

我不确定这可能是工作。

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

最新更新