2D ゲームに admob を実装しました。このゲームの開発に cocos2d を使用しています。admob バナーの位置を設定するのに誰か助けてくれませんか。縦向きのユニバーサル ゲームを持っています。デバイスの下部にバナーを表示したいのですが、現在、あるビューから別のビューに移動するとバナーが削除され、削除されません。ここに私のコードがあります:
-(void)onEnter
{
[super onEnter];
#ifdef ENABLE_ADMOB
// AppDelegate *app=(AppDelegate*)[[UIApplication sharedApplication]delegate];
viewController = [(AppDelegate *)[[UIApplication sharedApplication] delegate] viewController];
// AppController *app = (AppController*)[[UIApplication sharedApplication] delegate];
// Create a view of the standard size at the bottom of the screen.
// Available AdSize constants are explained in GADAdSize.h.
mBannerView = [[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner];
// Specify the ad's "unit identifier." This is your AdMob Publisher ID.
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
mBannerView.adUnitID =@"a15062384653c9e";
}
else
{
mBannerView.adUnitID =@"a15062392a0aa0a";
}
// Let the runtime know which UIViewController to restore after taking
// the user wherever the ad goes and add it to the view hierarchy.
//size
mBannerView.rootViewController = viewController;
[viewController.view addSubview:mBannerView];
// Initiate a generic request to load it with an ad.
[mBannerView loadRequest:[GADRequest request]];
CGRect frame = mBannerView.frame;
frame.origin.y = (viewController.view.bounds.size.height) ;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
CGSize AdSize = kGADAdSizeLeaderboard.size;
frame.origin.y = 950;
}
else
{
CGSize AdSize = kGADAdSizeBanner.size;
frame.origin.y = 430;
}
mBannerView.frame = frame;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
frame = mBannerView.frame;
frame.origin.y = 430;
mBannerView.frame = frame;
[UIView commitAnimations];
#endif
}
-(void)showBannerView
{
if (mBannerView)
{
[UIView animateWithDuration:0.5
delay:0.1
options: UIViewAnimationCurveEaseOut
animations:^
{
CGRect frame = mBannerView.frame;
frame.origin.x = 0;
mBannerView.frame = frame;
}
completion:^(BOOL finished)
{
}];
}
}
-(void)hideBannerView
{
if (mBannerView)
{
[UIView animateWithDuration:0.5
delay:0.1
options: UIViewAnimationCurveEaseOut
animations:^
{
CGRect frame = mBannerView.frame;
frame.origin.y = -50.0f;
mBannerView.frame = frame;
}
completion:^(BOOL finished)
{
}];
}
}
-(void)dismissAdView
{
#ifdef ENABLE_ADMOB
if (mBannerView)
{
[UIView animateWithDuration:0.5
delay:0.1
options: UIViewAnimationCurveEaseOut
animations:^
{
CGRect frame = mBannerView.frame;
frame.origin.y = -50.0f;
mBannerView.frame = frame;
}
completion:^(BOOL finished)
{
[mBannerView setDelegate:nil];
[mBannerView removeFromSuperview];
mBannerView = nil;
}];
}
#endif
}