简体   繁体   English

iAd横幅广告在iPhone 6/6 Plus上的位置错误

[英]iAd banner position is wrong on iPhone 6/6 Plus

I'm trying to optimize my SpriteKit App for iPhone 6 and iPhone 6 Plus but the iAd banner position is wrong and I can't change it. 我正在尝试针对iPhone 6和iPhone 6 Plus优化我的SpriteKit应用程序,但iAd标语位置错误,我无法更改。 It works great on 4" or 3.5" iPhones but on iPhone 6 and 6 Plus the banner isn't at the bottom, it is a bit above it. 它在4英寸或3.5英寸iPhone上运行良好,但在iPhone 6和6 Plus上,横幅不在底部,而是在其上方。

Also, I've been searching for this problem in google. 另外,我一直在谷歌搜索这个问题。 There were many solutions but none of them worked for me. 有很多解决方案,但是没有一个对我有用。

I'm using following code for the iAd banner in my ViewController.m file: 我在ViewController.m文件中为iAd横幅使用以下代码:

//iAd
#pragma mark iAd Delegate Methods

- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
    CGRect screen = [[UIScreen mainScreen] bounds];
    CGFloat height = CGRectGetHeight(screen);

    banner.frame = CGRectOffset(banner.frame, 0, height-banner.frame.size.height);
    //Changing the Y-position doesn't change the banner's position

    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:1];

    if([[NSUserDefaults standardUserDefaults] boolForKey:@"Ads_savedata"] == NO)
        [banner setAlpha:0];
    else
        [banner setAlpha:1];

    [banner updateConstraints];
    [UIView commitAnimations];
}

- (void) bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:1];
    [banner setAlpha:0];
    [UIView commitAnimations];
}

For me, it looks like the following line doesn't affect the banner's position. 对我来说,以下行似乎不影响横幅的位置。

banner.frame = CGRectOffset(banner.frame, 0, height-banner.frame.size.height);

I hope someone can help me with that problem. 我希望有人可以帮助我解决这个问题。 Thanks for your attention. 感谢您的关注。

I guess its screen width and height problem. 我猜它的屏幕宽度和高度问题。 Try this once 尝试一次

float SW;
float SH;
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
if (( [[[UIDevice currentDevice] systemVersion] floatValue]<8)  && UIInterfaceOrientationIsLandscape(orientation))
{
    SW = [[UIScreen mainScreen] bounds].size.height;
    SH = [[UIScreen mainScreen] bounds].size.width;
}
else
{
    SW = [[UIScreen mainScreen] bounds].size.width;
    SH = [[UIScreen mainScreen] bounds].size.height;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM