简体   繁体   中英

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. 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.

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:

//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;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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