2010-07-02 70 views
3

我在iPhone應用程序中整合了iAd時遇到了問題 - 廣告效果不佳時(請參閱http://www.clingmarks.com/iAd1.pnghttp://www.clingmarks.com/iAd2.png),但當我關閉它時,會留下白色空白屏幕(見http://www.clingmarks.com/iAd3.png)。我無法弄清楚爲什麼。下面是我如何整合廣告:iAd在關閉後留下白色空白屏幕

因爲我需要爲iPhone操作系統的較低版本支持其他的廣告,我的應用程序,其視圖控制器是AdViewController的頂部添加一個容器視圖。加載視圖時,我通過編程方式創建AdBannerView,並將其作爲子視圖添加到AdViewController.view中。這裏是viewDidLoad方法的代碼:

Class adClass = (NSClassFromString(@"ADBannerView")); 
if (adClass != nil) { 
    iAdView = [[ADBannerView alloc] initWithFrame:CGRectZero]; 
    iAdView.frame = CGRectOffset(iAdView.frame, 0, -50); 
    iAdView.requiredContentSizeIdentifiers = [NSSet setWithObject:ADBannerContentSizeIdentifier320x50]; 
    iAdView.currentContentSizeIdentifier = ADBannerContentSizeIdentifier320x50; 
    iAdView.delegate = self; 
    iadViewIsVisible = NO; 
    [self.view addSubview:iAdView]; 
} else { 
     // init google adsense 
    } 

以下是委託方法:

enter code here 
- (void)bannerViewDidLoadAd:(ADBannerView *)banner { 
if (!iadViewIsVisible) { 
    [UIView beginAnimations:@"animateAdBannerOn" context:NULL]; 
    // banner is invisible now and moved out of the screen on 50 px 
    banner.frame = CGRectOffset(banner.frame, 0, 50); 
    [UIView commitAnimations]; 
    iadViewIsVisible = YES; 
} 
} 

- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error { 
if (iadViewIsVisible) { 
    [UIView beginAnimations:@"animateAdBannerOff" context:NULL]; 
    // banner is visible and we move it out of the screen, due to connection issue 
    banner.frame = CGRectOffset(banner.frame, 0, -50); 
    [UIView commitAnimations]; 
    iadViewIsVisible = NO; 
} 
} 
+0

你可以幫我在這http://stackoverflow.com/questions/5953418/implementation-for-iad – ajay 2011-05-11 07:28:03

回答

4

最後我想通了自己。事實證明,ADBannerView的父視圖必須是全屏視圖。我上面的情況,我添加了AdBannerView到我的adView,這是一個大小爲320x50的視圖。當我將其父視圖更改爲全屏視圖時,一切正常。我不確定這是否是iAd中的錯誤,但肯定有些棘手。

1

當橫幅完成後,它移動本身,即使這意味着具有負y座標在屏幕的頂部。當它結束時,我把旗幟居中。在我的情況下,只有橫幅廣告有一個視圖控制器,所以點擊廣告時只有全屏顯示。

-(void) bannerViewActionDidFinish:(UIView *)inBanner { 
    CGRect      frame = [inBanner frame]; 

    frame.origin.x = frame.size.width * 0.5; 
    frame.origin.y = frame.size.height * 0.5; 

    [inBanner setCenter:frame.origin]; 
} 
1

嘿大衛!我知道你的意思,我也使用自己的AdvertisementViewController來調用不同的廣告網絡。

因此iAd的不是全屏視圖,但320x50的視圖中。

只要做到這一點:

-(void) bannerViewActionDidFinish:(ADBannerView *)inBanner { 

[self.view setFrame:CGRectMake(0.0f, 0.0f, 320.0f, 50.0f)]; 

} 

所以外觀圖容器(self.view)被調整到原來的大小。在顯示iAd時,iAd會將其大小調整爲全屏顯示廣告。