Ajouter ADBannerView à un SKScene

J'essaie d'append une bannière iAd à mon jeu sur scène, mais je ne sais pas comment append UIView à un SKScene.

Le controller de vue d'application est:

- (void)viewWillLayoutSubviews { [super viewWillLayoutSubviews]; // Configure the view. SKView * skView = (SKView *)self.view; skView.showsFPS = YES; skView.showsNodeCount = YES; // Create and configure the scene. SKScene * scene = [GameOverScene sceneWithSize:skView.bounds.size andScore:0]; scene.scaleMode = SKSceneScaleModeAspectFill; // Present the scene. [skView presentScene:scene]; } 

et le GameOverScene:

 #import "GameOverScene.h" #import <iAd/iAd.h> @implementation GameOverScene +(id)sceneWithSize:(CGSize)size andScore:(NSInteger)score{ return [[self alloc] initWithSize:size andScore:score]; } -(id)initWithSize:(CGSize)size andScore:(NSInteger)score{ if (self = [super initWithSize:size]) { /* Setup your scene here */ self.backgroundColor = [SKColor colorWithRed:0.15 green:0.15 blue:0.3 alpha:1.0]; //some stuff here... ADBannerView* banner = [[ADBannerView alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height - 50, 320, 50)]; [self.scene.view addSubview:banner]; //[self.view addSubview:banner]; } return self; } @end 

Une idée ou une suggestion? Merci!

Utilisez NSNotificationCenter. Pour le rendre simple pour vous:

1) Ajoutez un AdBannerView dans le storyboard à l'intérieur du SKView. (Ou vous pouvez append en utilisant le code dans votre ViewController.m)

2) Dans votre ViewController.h, définissez ADBannerViewDelegate et ajoutez-y (n'oubliez pas de lier la sortie dans le storyboard)

 @property (weak, nonatomic) IBOutlet ADBannerView *banner; 

3) Dans votre ViewController.m

 - (void)viewDidLoad { self.banner.hidden = YES; //Add view controller as observer [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleNotification:) name:@"hideAd" object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleNotification:) name:@"showAd" object:nil]; } - (void)showBanner { self.banner.hidden = NO; } - (void)hidesBanner { self.banner.hidden = YES; } //Handle Notification - (void)handleNotification:(NSNotification *)notification { if ([notification.name isEqualToSsortingng:@"hideAd"]) { [self hidesBanner]; }else if ([notification.name isEqualToSsortingng:@"showAd"]) { [self showBanner]; } } 

4) Dans votre Scene.m, afin d'afficher l'annonce

par exemple, le joueur est mort et vous voulez montrer la bannière

 // Show banner when iad loads [[NSNotificationCenter defaultCenter] postNotificationName:@"showAd" object:nil]; //Sends message to viewcontroller to show ad. 

5) Dans votre Scene.m, afin de cacher l'annonce

par exemple, le joueur a redémarré le jeu

 // Show banner when iad loads [[NSNotificationCenter defaultCenter] postNotificationName:@"hideAd" object:nil]; //Sends message to viewcontroller to show ad. 

* Conseiller cacher l'annonce quand il n'est pas chargé.

http://www.yokeharn.com/workflow-how-to-create-flappy-bird-game-in-3-days-day-3/ Faites défiler jusqu'à l'heure 4: iAd. Ceci est un bon tutoriel qui vous aide pour 90% les 10 derniers% que vous pouvez vous essayer