2012-10-08 71 views
5

我試圖在我的應用程序中加入iAdSuite選項卡欄視圖實現,我在套件和我的應用程序中看到了同樣的問題。當廣告出現時,我的內容視圖得到適當調整,廣告正確顯示。當廣告消失後,它會留下它所在的空白空間。不過,我已確認我的內容視圖的大小已恢復到其原始高度,並且已被拉低至其原始邊界。你只是看不到廣告所在的部分。我已經確定每個視圖都會得到一個layoutIfNeeded,並且幾乎所有我能想到的都無濟於事。有什麼想法嗎?iAdSuite bug在廣告消失時留下空白空間

enter image description here

編輯:我已經想通了什麼問題。每次showBannerView被調用時,Apple的示例顯然都會將_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]; 
} 

回答

0

我有同樣的問題。從hideBannerView委託方法的超級視圖中移除bannerview似乎解決了這個問題。

- (void)hideBannerView:(ADBannerView *)bannerView animated:(BOOL)animated 
{ 
    [self layoutAnimated:animated]; 
    [_bannerView removeFromSuperview]; 
    _bannerView = nil; 
} 
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]; 

} 
相關問題