Ios 在我向ViewController添加iAd横幅时调用了两次SKScene
我发现当我的viewcontroller中有iad横幅时,我的主菜单场景被调用了两次。有人知道它为什么这样做吗Ios 在我向ViewController添加iAd横幅时调用了两次SKScene,ios,sprite-kit,iad,Ios,Sprite Kit,Iad,我发现当我的viewcontroller中有iad横幅时,我的主菜单场景被调用了两次。有人知道它为什么这样做吗 -(void)bannerViewDidLoadAd:(ADBannerView *)banner{ [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:1]; [banner setAlpha:1]; [UIView commitAnimations];
-(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>{
@interface GameViewController:UIViewController{
我认为UIView可能有问题,因为我听说UIView不能很好地与Sprite工具包配合使用我不确定这是否可行 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];
你能显示你的代码吗?你试过用通知打电话吗?现在当你用模拟器运行时出现的广告甚至没有出现。但是没有。我没有试着用通知打电话这是个好主意。我的问题是,不管横幅是否隐藏,它都会加载我的场景两次。你有什么想法吗?