アプリに iAdSuite タブ バー ビューの実装を取り込もうとしていますが、スイートとアプリで同じ問題が発生しています。広告が表示されると、コンテンツ ビューのサイズが適切に変更され、広告が正しく表示されます。広告が消えると、広告があった場所に余白が残ります。ただし、コンテンツ ビューが元の高さにサイズ変更され、元の境界まで引き下げられることを確認しました。広告があった部分が見えないだけです。私はすべてのビューがlayoutIfNeededを取得することを確認しましたが、それ以外のほとんどすべてが役に立たないようにしました。何かご意見は?
編集:問題が何であるかを理解しました。Apple の例では、showBannerView: が呼び出されるたびに _bannerView を self.view に追加しているようですが、ビューを削除することはありません。バナー ビューが画面外に移動されているため、これでも完全には意味がありませんが、それを削除すると空白の問題は解決します。私の解決策は次のとおりですが、もっとエレガントな方法があれば教えてください。
- (void)layoutAnimated:(BOOL)animated {
if (UIInterfaceOrientationIsPortrait(self.interfaceOrientation)) {
_bannerView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
} else {
_bannerView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierLandscape;
}
CGRect contentFrame = self.view.bounds;
contentFrame.origin = CGPointMake(0.0, 0.0);
CGRect bannerFrame = _bannerView.frame;
if (_bannerView.bannerLoaded) {
contentFrame.size.height -= _bannerView.frame.size.height;
bannerFrame.origin.y = contentFrame.size.height;
} else {
bannerFrame.origin.y = contentFrame.size.height;
}
[UIView animateWithDuration:animated ? 0.25 : 0.0 animations:^{
_contentView.frame = contentFrame;
[_contentView layoutIfNeeded];
_bannerView.frame = bannerFrame;
}
completion:^(BOOL finished) {
if (!_bannerView.bannerLoaded) {
[_bannerView removeFromSuperview];
_bannerView=nil;
}
}];
}
- (void)showBannerView:(ADBannerView *)bannerView animated:(BOOL)animated
{
_bannerView = bannerView;
if (![self.view.subviews containsObject:_bannerView])
[self.view addSubview:_bannerView];
[self layoutAnimated:animated];
}
- (void)hideBannerView:(ADBannerView *)bannerView animated:(BOOL)animated
{
[self layoutAnimated:animated];
}