I checked around the net and found some people looking for this, but nobody who actually posted a code example. So here it is, code to make your Ad Mob ad shift to landscape orientation. My code makes it appear on the bottom, enlarged a little bit, with the device rotated to landscape counter-clockwise.
Add in a UIView called adContainer in your delegate interface declaration, and then update the standard Ad Mob methods as follows.
- (void)showAd { adMobAd = [AdMobView requestAdWithDelegate:self]; // start a new ad request [adMobAd retain]; // this will be released when it loads (or fails to load) adContainer = [[UIView alloc] initWithFrame:CGRectMake(0, 432, 320, 48)]; }
#define degreesToRadians(x) (M_PI * x / 180.0) - (void)didReceiveAd:(AdMobView *)adView { [adContainer addSubview: adMobAd]; [window addSubview:adContainer]; CGAffineTransform makeLandscape = CGAffineTransformMakeRotation(degreesToRadians(90)); makeLandscape = CGAffineTransformTranslate(makeLandscape, -480/2 + 48/2, 320/2 - 48/2 - 12); makeLandscape = CGAffineTransformScale(makeLandscape, 480.0/320, 480.0/320); adContainer.transform = makeLandscape; autoslider = [NSTimer scheduledTimerWithTimeInterval:AD_REFRESH_PERIOD target:self selector:@selector(refreshAd:) userInfo:nil repeats:YES]; }
- (void)removeAd { [adMobAd removeFromSuperview]; [adMobAd release]; adMobAd = nil; [adContainer removeFromSuperview]; [adContainer release]; adContainer = nil; }
This was actually my first experience using the CG transforms, so please be gentle if there’s a better way
.