iAd frame returning wrong height on iPhone

橙三吉。 提交于 2019-12-11 21:19:31

问题


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.


回答1:


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;


来源:https://stackoverflow.com/questions/22132113/iad-frame-returning-wrong-height-on-iphone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!