Ios6 单击后iAd自动布局问题

Ios6 单击后iAd自动布局问题,ios6,iad,autolayout,Ios6,Iad,Autolayout,我在“测试广告商”iAd横幅上clic时遇到一些布局问题: 我不明白,因为在我点击横幅之前,一切都显示得很好 我正在使用自动布局。 这是我的视图层次结构 UIView | 内容视图 |导航栏 |桌面视图 |横幅视图 我保留了contentView底部约束和bannerView底部约束的引用 这是我的密码: - (id)init { self = [super init]; if (self) { _eventsController = [[Event

我在“测试广告商”iAd横幅上clic时遇到一些布局问题:

我不明白,因为在我点击横幅之前,一切都显示得很好

我正在使用自动布局。

这是我的视图层次结构 UIView | 内容视图 |导航栏 |桌面视图 |横幅视图

我保留了contentView底部约束和bannerView底部约束的引用

这是我的密码:

- (id)init
{
    self = [super init];
    if (self)
    {
        _eventsController = [[EventsController alloc]init];
        if ([[NSUserDefaults standardUserDefaults] boolForKey:@"showADs"])
        {
            NSLog(@"Show ADs");
            _bannerView = [[ADBannerView alloc] initWithAdType:ADAdTypeBanner];
            [self.bannerView setDelegate:self];
        }
    }
    return self;
}
视图显示

- (void)viewDidAppear:(BOOL)animated
    {
    [super viewDidAppear:animated];

    NSLog(@"viewDidAppear");
    if ([[NSUserDefaults standardUserDefaults] boolForKey:@"showADs"])
    {
        [self.view addSubview:self.bannerView];
        [self.bannerView setTranslatesAutoresizingMaskIntoConstraints:NO];

        [self.view addConstraint:[NSLayoutConstraint constraintWithItem:self.bannerView
                                                             attribute:NSLayoutAttributeLeading
                                                             relatedBy:NSLayoutRelationEqual
                                                                toItem:self.contentView
                                                             attribute:NSLayoutAttributeLeading
                                                             multiplier:1.0 constant:0]];

        self.bannerviewBottomConstraint = [NSLayoutConstraint constraintWithItem:self.bannerView
                                     attribute:NSLayoutAttributeBottom
                                     relatedBy:NSLayoutRelationEqual
                                        toItem:self.contentView
                                     attribute:NSLayoutAttributeBottom
                                    multiplier:1.0 constant:50];
        [self.view addConstraint:self.bannerviewBottomConstraint];
        [self.view setNeedsUpdateConstraints];
        [self.view setNeedsLayout];
    }
}
AdBannerViewDelegate

#pragma mark - ADBannerView Delegate
- (void)updateLayoutForAD
{
    if (self.bannerView.bannerLoaded)
    {
        self.contentViewBottomConstraint.constant = -50.0;
        self.bannerviewBottomConstraint.constant = 0;
    }
    else
    {
        self.contentViewBottomConstraint.constant = 0;
        self.bannerviewBottomConstraint.constant = 50;
    }

    [self.view setNeedsUpdateConstraints];
    [UIView animateWithDuration:0.25 animations:^{
        [self.view layoutIfNeeded];
    }];
}

- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
    NSLog(@"GOT AD");    
    [self updateLayoutForAD];
}

- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
    NSLog(@"DIDN'T GOT AD");
    [self updateLayoutForAD];
}