简体   繁体   English

始终将iAD标语放置在屏幕底部(IOS 7)

[英]Placing iAD banner always at the bottom of the screen(IOS 7)

So I am implementing the singleton iAD system and I got the function that adds the banner on the view, but how can I make sure that the banner is always on the bottom so it works with both 3.5inch and 4inch screen? 因此,我正在实现单例iAD系统,并且获得了在视图上添加横幅的功能,但是如何确保横幅始终位于底部,因此它可以同时在3.5英寸和4英寸屏幕上使用?

Here is my code but the banner won't position correctly, it goes off screen 这是我的代码,但是横幅无法正确定位,它不在屏幕上

-(void)attachBannerToViewController:(UIViewController*)viewController
{

    if (_iAdBanner == nil) {
        NSLog(@"iAdbanner alloc");
        _iAdBanner = [[ADBannerView alloc] initWithAdType:ADAdTypeBanner];
        _iAdBanner.delegate = self;
        _iAdBanner.alpha = 0.0;
    }

    CGRect frame=CGRectZero;
    frame.size = _iAdBanner.frame.size;
    frame.origin = CGPointMake(0.0, viewController.view.frame.size.height-_iAdBanner.frame.size.height);

    [_iAdBanner setFrame:frame];
    [viewController.view addSubview:_iAdBanner];
}

At a guess, I'd say you are running this code before you view controller has finished all it's setup. 猜测一下,我认为您正在运行此代码,然后查看控制器已完成所有设置。 When you run this line of code it will be correct, but by the time the view controller.view gets added to the window it will be wrong. 当您运行此行代码时,它将是正确的,但是到将view controller.view添加到window这将是错误的。

Consider setting up your auto-resizing flags or constraints to keep the ad banner in the correct position. 考虑设置自动调整大小标志或约束,以将广告横幅保持在正确的位置。 Which are you using? 您正在使用哪个?

_iAdBanner.autoresizingMask = UIViewAutoresizingFlexibleTopMargin|UIViewAutoresizingFlexibleWidth;

Constraints.... someone else just posted and answer for setting it up with constraints so I won't duplicate their work. 约束...。其他人刚刚发布并回答了设置约束的问题,所以我不会重复他们的工作。 :) :)

You could use NSLayoutConstraint : 您可以使用NSLayoutConstraint

-(void)attachBannerToViewController:(UIViewController*)viewController
{
    if (_iAdBanner == nil) {
        NSLog(@"iAdbanner alloc");
        _iAdBanner = [[ADBannerView alloc] initWithAdType:ADAdTypeBanner];
        _iAdBanner.delegate = self;
        _iAdBanner.alpha = 0.0;
        _iAdBanner.translatesAutoresizingMaskIntoConstraints = NO;
        [viewController.view addSubview:_iAdBanner];
        [viewController.view addConstraints:
         [NSLayoutConstraint
          constrainsWithVisualFormat:@"|-0-[banner]-0-|"
          options:0
          metrics:nil
          views:@{"banner" : _iAdBanner}]];
        [viewController.view addConstraints:
         [NSLayoutConstraint
          constrainsWithVisualFormat:@"V:[banner]-0-|"
          options:0
          metrics:nil
          views:@{"banner" : _iAdBanner}]];
    }
}

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

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