2014-10-29 46 views
1

我使用UITabBarController-iAds的修改版本使iAds幾乎完美地工作。我唯一的問題是第一個廣告加載我的觀點被覆蓋。一旦廣告在30秒後刷新,視圖的大小就可以調整。iAd涵蓋了我對第一次加載的看法

我用下面的代碼:

- (void)layoutBanner 
{ 
    float height = 0.0; 
    ADBannerView *_banner = (ADBannerView *)[self.view viewWithTag:12]; 
    CGRect bounds = [UIScreen mainScreen].bounds; 

    if (UIInterfaceOrientationIsPortrait(self.interfaceOrientation)) { 
     _banner.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait; 
    } else { 
     _banner.currentContentSizeIdentifier = ADBannerContentSizeIdentifierLandscape; 
    } 

    //When compiling against iOS 8 SDK this needs to be height, regardless of the actual device orientation 
    height = bounds.size.height; 

    CGSize bannerSize = [ADBannerView sizeFromBannerContentSizeIdentifier:_banner.currentContentSizeIdentifier]; 

    //Get content view 
    UIView *_contentView = self.selectedViewController.view; 

    CGRect contentFrame = _contentView.frame; 
    CGRect bannerFrame = _banner.frame; 

    if (_banner.isBannerLoaded) { 
     if (iOS7) { 
      contentFrame.size.height = height - bannerSize.height; 
      bannerFrame.origin.y = contentFrame.size.height - self.tabBar.frame.size.height; 
     } else { 
      contentFrame.size.height = height - self.tabBar.frame.size.height - bannerSize.height; 
      bannerFrame.origin.y = contentFrame.size.height; 
     } 
    } else { 
     if (iOS7) { 
      contentFrame.size.height = height; 
      bannerFrame.origin.y = bounds.size.height; 
     } else { 
      contentFrame.size.height = height - self.tabBar.frame.size.height; 
      bannerFrame.origin.y = bounds.size.height; 
     } 
    } 

    [UIView animateWithDuration:0.25 animations:^{ 
     _banner.frame = bannerFrame; 
     _contentView.frame = contentFrame; 
    } completion:^(BOOL finished) { 
     [self.view bringSubviewToFront:_banner]; 
    }]; 
} 

- (void)bannerViewDidLoadAd:(ADBannerView *)banner 
{ 
    NSLog(@"Did load"); 
    [self layoutBanner]; 
} 

任何想法?

回答

2

我設法解決這個問題,通過玩動漫動畫塊。我移動了內容視圖行,它解決了問題

[UIView animateWithDuration:0.25 animations:^{ 
_banner.frame = bannerFrame; 
} completion:^(BOOL finished) { 
    _contentView.frame = contentFrame; 
    [self.view bringSubviewToFront:_banner]; 
}]; 
0

我不是100%肯定,但我想這個問題是關係到:

[self.view bringSubviewToFront:_banner]; 

整個動畫:

[UIView animateWithDuration:0.25 animations:^{ 
     _banner.frame = bannerFrame; 
     _contentView.frame = contentFrame; 
    } completion:^(BOOL finished) { 
     [self.view bringSubviewToFront:_banner]; 
    }]; 

是有些奇怪,因爲在完成塊你將橫幅視圖放在前面,所以我可以假設在動畫開始之前 - 橫幅已被其他一些視圖或視圖覆蓋 - 如果橫幅視圖被覆蓋,框架動畫的原因是什麼?因此在動畫處於不可見狀態時進展?

當然,這個問題只適用於第一次運行。

+0

嗯是的我想我遵循你的邏輯。廣告加載後,佈局會更新,以指定您對齊的廣告的位置,然後對其進行動畫製作。蘋果公司的實施情況稍有不同,所以我可以試一試。 – Leon 2014-11-07 10:15:46

+0

嘗試添加「[self.view bringSubviewToFront:_banner];」到實現橫幅的控制器的viewDidLoad方法。讓我知道結果。 – 2014-11-08 20:22:20

+0

我不能這樣做,因爲我發佈的代碼是在一個類別而不是ViewController。 – Leon 2014-11-09 23:03:13

0
  1. 爲iOS8上[UIScreen mainScreen]界限]已經改變..以前它總是返回肖像(其中H> W)值,無論interfaceOrientation的,但現在看來要尊重接口方向... (這不是一件壞事,除非你正在做以前的行爲是理所當然的)

  2. 你爲什麼不嘗試CGRectGetMinY(的CGRect aRect)..

如。 (我可是從你的代碼的旗幟在屏幕底部進入,而在頂部您的TabBar假設。(我認爲這是奇怪的..))

//once you have calculated bannerFrame 

    contentFrame.size.height = (CGRectGetMinY(bannerFrame) - CGRectGetMinY (contentView.frame) ); 

contentFrame.origin.y = CGRectGetMaxY(self.tabbar.frame); 
  • 你有任何約束/ resizingMasks設置?當你加載第二個廣告視圖控制器的視圖已經調整大小,以適應廣告,大概是第一個廣告是試圖改變的東西..
  • +0

    1.是的。 2。不,標籤欄位於底部,廣告位於其上方。你能詳細說明嗎? – Leon 2014-11-07 10:06:01

    相關問題