【问题标题】:iAdSuite bug leaves white space when ad disappears当广告消失时,iAdSuite 错误会留下空白
【发布时间】:2012-10-08 15:45:36
【问题描述】:

我正在尝试将 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];
}

【问题讨论】:

    标签: objective-c ios xcode


    【解决方案1】:

    我遇到了同样的问题。在 hideBannerView 委托方法中从超级视图中删除横幅视图似乎已经解决了。

    - (void)hideBannerView:(ADBannerView *)bannerView animated:(BOOL)animated
    {
        [self layoutAnimated:animated];
        [_bannerView removeFromSuperview];
        _bannerView = nil;
    }
    

    【讨论】:

      【解决方案2】:

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

      - (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];
      
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-07-20
        • 2015-02-09
        • 1970-01-01
        • 2017-01-09
        • 1970-01-01
        • 1970-01-01
        • 2021-10-02
        • 1970-01-01
        相关资源
        最近更新 更多