2011-11-04 71 views
-1
- (void)viewDidLoad 
{ 

    adView = [[ADBannerView alloc] initWithFrame:CGRectZero]; 
    adView.requiredContentSizeIdentifiers = [NSSet setWithObject:ADBannerContentSizeIdentifierPortrait]; 
    adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait; 
    CGRect adFrame = adView.frame; 
    adFrame.origin.y = self.view.frame.size.height-adView.frame.size.height; 
    adView.frame = adFrame; 
    [self.view addSubview:adView]; 

} 


- (void)bannerViewDidLoadAd:(ADBannerView *)banner 
{ 
    if (!self.bannerIsVisible) 
    { 
     self.bannerIsVisible = YES; 
    } 
} 

- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error 
{ 
    if (self.bannerIsVisible) 
    { 

     self.bannerIsVisible = NO; 
    } 

回答

2

有四件事。首先,您應該將banner放置在viewDidLoad方法的屏幕外,因爲它會在第一次啓動時顯示空幀,並且很可能因此而被拒絕。

其次,您正在設置您的橫幅視圖不正確。我認爲該框架仍然是CGZero。第三,你沒有設置bannerView的委託。請嘗試以下操作:

-(void)viewDidLoad{ 
    CGRect frame=CGRectZero; 
    frame.size = [ADBannerView sizeFromBannerContentSizeIdentifier:ADBannerContentSizeIdentifierPortrait]; 
    // Place frame at the bottom edge of the screen out of sight 
    frame.origin = CGPointMake(0.0, CGRectGetMaxY(self.view.bounds)); 

    // Now to create and configure the banner view 
    ADBannerView *adView = [[ADBannerView alloc] initWithFrame:frame]; 
    adView.requiredContentSizeIdentifiers = [NSSet setWithObject:ADBannerContentSizeIdentifierPortrait]; 
    // Set the delegate to self, so that we are notified of ad responses 
    adView.delegate = self; 
    [self.view addSubview: adView]; 
} 

第四,在你的bannerViewDidLoadAd:方法你是不是動畫橫幅廣告到位。試試這個:

- (void)bannerViewDidLoadAd:(ADBannerView *)banner 
{ 
    // Get a brand new frame 
    CGRect newFrame=CGRectZero; 
    CGPoint frameOrigin=CGPointZero; 
    // Set the origin 
    frameOrigin=CGPointMake(0.0, CGRectGetMaxY(self.view.bounds)); 
    newFrame.origin=frameOrigin; 

    // Set the size 
    newFrame.size=[ADBannerView sizeFromBannerContentSizeIdentifier:ADBannerContentSizeIdentifierPortrait]; 

    CGFloat bannerHeight = newFrame.size.height; 
    CGFloat bannerOffset=0.0; 

    // Determine where the new frame should be 
    if (!self.bannerIsVisible) 
    { 
     // It should be visible, raise it up 
     bannerOffset=-bannerHeight; 
    } 

    CGRect offSetRect=CGRectOffset(newFrame,0.0f,bannerOffset); 
     [UIView animateWithDuration:0.2 
         animations:^{banner.view.frame=offSetRect} 
         completion:^(BOOL finished){ 
          if (bannerOffSet<0){ 
           self.bannerIsVisible=YES; 
          }else{ 
           self.bannerIsVisible=NO; 
          } 
         } 
     ]; 

} 

當然,如果旗幟,是應該被放置在屏幕的上方,你可以大概判斷出事情需要如何進行修改,但是這讓你在正確的方向前進。

祝你好運

0

不知道通過閱讀您的問題,但請注意蘋果模擬iAds不可用。有時候你需要在樣本廣告出現之前嘗試多次。

+0

它從不顯示 – jini