5

アプリに 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];
}
4

2 に答える 2

0

私も同じ問題を抱えていました。hideBannerViewデリゲートメソッドのスーパービューからバナービューを削除すると解決したようです。

- (void)hideBannerView:(ADBannerView *)bannerView animated:(BOOL)animated
{
    [self layoutAnimated:animated];
    [_bannerView removeFromSuperview];
    _bannerView = nil;
}
于 2012-10-13T05:53:51.527 に答える
0

この質問と回答をありがとう、私はこれで髪を引っ張っていました。このように気の毒なコードを変更したところ、非表示のアニメーションが機能するようになりました。Apple がなぜバグのあるサンプル コードを公開しているのか不思議です...

- (void)layoutAnimated:(BOOL)animated hide:(BOOL)hide
{
    if (UIInterfaceOrientationIsPortrait(self.interfaceOrientation)) {
        _bannerView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
    } else {
        _bannerView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierLandscape;
    }

    CGRect contentFrame = self.view.bounds;


    CGRect bannerFrame = _bannerView.frame;
    if (!hide) {
        contentFrame.size.height -= _bannerView.frame.size.height;
        bannerFrame.origin.y = contentFrame.size.height;
    } else {
        contentFrame.size.height += _bannerView.frame.size.height;
        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 (hide) {
            [_bannerView removeFromSuperview];
            _bannerView=nil;
        }
    }];
}

- (void)showBannerView:(ADBannerView *)bannerView animated:(BOOL)animated
{
    _bannerView = bannerView;
    [self.view addSubview:_bannerView];
    [self layoutAnimated:animated hide:NO];
}

- (void)hideBannerView:(ADBannerView *)bannerView animated:(BOOL)animated
{
    [self layoutAnimated:animated hide:YES];

}
于 2013-02-27T00:54:26.827 に答える