Reputation: 1829
I want to add admob "smart banners" at the bottom of the portrait screen. But the code show the adds at the top of screen. Here is my code
cocos2d::CCSize size = cocos2d::CCDirector::sharedDirector()->getWinSize();
CGPoint origin = CGPointMake(size.width,0.0);
bannerView_ = [[[GADBannerView alloc]
initWithAdSize:kGADAdSizeSmartBannerPortrait
origin:origin] autorelease];
No matter how I change the origin the ads are showing at the top of the screen. Any help is highly appriciated. Thanks
Upvotes: 3
Views: 1753
Reputation: 1013
This is how I’ve achieved to show ad on bottom of the screen.
GADBannerView* bannerView_ = [[GADBannerView alloc] initWithAdSize:kGADAdSizeSmartBannerPortrait];
//For Positioning
float winHeight = viewController.view.frame.size.height;
float winWidth = viewController.view.frame.size.width;
//BannerView y-center is half of it's total height, and co-ordinates have to be calculated with TOP-Left as (0,0). Multiplied by 0.5 for y-center of banner view.
bannerView_.center=CGPointMake(winWidth/2, winHeight - 0.50 * bannerView_.frame.size.height);
//bannerView_.autoresizingMask = UIViewAutoresizingFlexibleTopMargin;
// Let the runtime know which UIViewController to restore after taking
// the user wherever the ad goes and add it to the view hierarchy.
bannerView_.rootViewController = viewController;
[viewController.view addSubview:bannerView_];
GADRequest * request = [GADRequest request];
request.testDevices = [NSArray arrayWithObjects:
GAD_SIMULATOR_ID, // Simulator
nil];
// Initiate a generic request to load it with an ad.
[bannerView_ loadRequest:request];
Upvotes: 2
Reputation: 8006
I did it this way : I create the banner without origin. Then when the ad is loaded, the - (void)adViewDidReceiveAd:(GADBannerView *)bannerView
delegate method gets fired, and in it I animate the banner to slide down from the top of the screen. Here is the code :
- (void)adViewDidReceiveAd:(GADBannerView *)bannerView {
self.adBannerView = bannerView;
[UIView animateWithDuration:0.5 delay:0.1 options: UIViewAnimationCurveEaseOut animations:^
{
CGSize s = [[CCDirector sharedDirector] winSize];
CGRect frame = self.adBannerView.frame;
frame.origin.y = 0;
self.adBannerView.frame = frame;
}
completion:^(BOOL finished)
{
}];
}
Upvotes: 0