「広告主のテスト」iAdバナーをクリックすると、レイアウトに問題があります。
バナーをクリックする前にすべてがうまく表示されているのでわかりません。
自動レイアウトを使用しています。
これが私のビュー階層UIViewです| ContentView | NavigationBar | Tableview | BannerView
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;
}
ViewDidAppear
- (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];
}