2010-07-02 71 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会将其大小调整为全屏显示广告。