iAd定位于iphone 5和iphone 4问题

时间:2014-09-03 03:53:00

标签: ios objective-c xcode storyboard iad

我有一个spritekit项目,我希望iAd出现在屏幕底部。我在屏幕底部使用了storyboardposition它。唯一的问题是,如果我将它放在iPhone 4屏幕的底部,它会在iPhone 5的中间结束,如果我将它放在iPhone 5屏幕的底部,没有显示在4.我使用banner.Center修复了这个问题一段时间但是当我更改viewsbanner没有重新加载所以它没有t显示在iPhone 4屏幕上。

    #pragma mark iAd Delegate Methods

-(void)bannerViewDidLoadAd:(ADBannerView *)banner{

    NSLog(@"SUCCESS");

    [UIView beginAnimations:nil context:NULL];

    [UIView setAnimationDuration:1];

    [banner setAlpha:1];

    [UIView commitAnimations];

    if (device == 4) {
        banner.center = CGPointMake(160, 455);
    }
    if (device == 5) {
        banner.center = CGPointMake(160, 543);
    }

    adIsThere = YES;
}


-(void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error{

    NSLog(@"ERROR");
    [UIView beginAnimations:nil context:NULL];

    [UIView setAnimationDuration:1];

    [banner setAlpha:0];

    [UIView commitAnimations];

    adIsThere = NO;


}

我找到了此链接但是当我点击storyboard和尺寸检查器上的广告时,autosizing部分没有显示....我认为它与事实是SpriteKit project

iad iPhone 5 Storyboard implementation

如果你能提供帮助,谢谢!

2 个答案:

答案 0 :(得分:2)

也许不是使用确切的数字设置位置,而是将其设置为屏幕底部减去横幅广告的尺寸。

CGFloat screenHeight = [[UIScreen mainScreen] bounds].size.height;
banner.center = CGPointMake(160, screenHeight - bannerView_.frame.size.height);

编辑:如果您正在使用故事板,可以尝试使用约束,右键单击从iAd横幅拖动到"视图"并选择"底部空间到底部布局指南"

enter image description here

答案 1 :(得分:1)

做这样的事情

if ([[UIScreen mainScreen] bounds].size.height==480)  //iPhone 4
{
 banner.center = CGPointMake(160, 455);
}
else if ([[UIScreen mainScreen] bounds].size.height==568) //iPhone 5
{
 banner.center = CGPointMake(160, 543);
}