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

感谢您提出这个问题和答案,我正在用这个拉头发。我像这样更改了该死的代码,现在隐藏动画起作用了。我想知道为什么苹果发布错误的示例代码......

- (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 回答