Satyam
Satyam

Reputation: 15902

iPhone - Handling AdMob Ad orientation

I integrated AdMob in my application. The ad is being shown at the bottom of the view. My App supports both Portrait and Landscape modes. When orientation is changed, how can I make sure that ad is being shown at the bottom only? I want to show ad in both orientations....

Any workarounds please...

Upvotes: 1

Views: 3526

Answers (2)

rocketgary
rocketgary

Reputation: 1

This is the code I came up with to center an AdMob ad at the bottom of the screen in landscape mode:

int x = (self.view.frame.size.width - CGSizeFromGADAdSize(kGADAdSizeBanner).width) / 2;
int y = self.view.frame.size.height - CGSizeFromGADAdSize(kGADAdSizeBanner).height - 2;

CGPoint origin = CGPointMake(x, y);

bannerScore = [[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner origin:origin];

bannerScore.adUnitID = @"xxxxxxxx";

bannerScore.rootViewController = self;
[self.view addSubview:bannerScore];

[bannerScore loadRequest:[GADRequest request]];

Upvotes: 0

Eric Leichtenschlag
Eric Leichtenschlag

Reputation: 8931

You will want to set the autoresize bit mask on your GADBannerView to make the top margin flexible when the device changes orientation. Assuming your GADBannerView is called "bannerView_", try:

    [bannerView_ setAutoresizingMask:UIViewAutoresizingFlexibleTopMargin];

The GADBannerView will not cover the entire width of the screen in landscape mode. If you want to center it on the bottom, for example, try:

    [bannerView_ setAutoresizingMask:UIViewAutoresizingFlexibleTopMargin|UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin];

You can play around with these autoresize bits to make it work for your app.

Upvotes: 7

Related Questions