Question

I have an iAd which I am trying to position at the bottom of the screen though when I try to get the height of the ad so that I can put it at the bottom. This error only occurs when I enter the screen in a landscape orientation as the ad is taller in the portrait orientation and only on the iPhone simulator as on an ipad the ads are the same height.

The method I am using to put the add at the bottom is by setting the y value of the ad frame to the height of the view minus the height of the ad.

Here is the code that I am currently using:

- (void)viewWillAppear:(BOOL)animated
{
    CGRect adFrame = banner.frame;
    adFrame.origin.y = screenHeight - banner.frame.size.height;
    adFrame.size.width = screenWidth;
    banner.frame = adFrame;
    [banner setAutoresizingMask:UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleWidth];
}

- (void)viewDidLoad 
{
    [super viewDidLoad];
    banner.frame = CGRectZero;
}

Any help would be much appreciated.

Was it helpful?

Solution

I would take a look at Apple's sample code for integrating iAD exactly how you describe, particularly in ContainerBanner/ContainerBanner/BannerViewController.m. What you are looking for is ADBannerView's - (CGSize)sizeThatFits:(CGSize)size.

CGRect adRect = CGRectZero;
CGRect contentFrame = self.view.bounds;
adRect.size = [banner sizeThatFits:contentFrame.size];
adRect.origin.y = CGRectGetHeight(contentFrame) - CGRectGetHeight(adRect);
banner.frame = adRect;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top