iAd关闭后留下白色空白屏幕

时间:2010-07-02 15:14:26

标签: iphone ios4 iad

我在我的iPhone应用程序中集成iAd时遇到了问题 - 横幅广告在消费时很好(请参阅http://www.clingmarks.com/iAd1.pnghttp://www.clingmarks.com/iAd2.png),但是当我关闭它时,它会留下白色空白屏幕(见http://www.clingmarks.com/iAd3.png)。我无法弄清楚为什么。以下是我整合广告的方式:

因为我需要为较低版本的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;
}
}

3 个答案:

答案 0 :(得分:4)

最终我自己弄清楚了。事实证明,ADBannerView的父视图必须是全屏视图。我上面的情况,我将AdBannerView添加到我的adView,这是一个大小为320x50的视图。当我将其父视图更改为全屏视图时,一切正常。我不确定这是否是iAd中的错误,但肯定是棘手的。

答案 1 :(得分: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];
}

答案 2 :(得分:1)

嘿大卫!我知道你的意思,我也在使用一个自己的广告视频控制器来调用不同的广告网络。

所以iAd不是全屏视图,而是在320x50视图中。

只需这样做:

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

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

}

因此外部视图容器(self.view)的大小调整为原始大小。 iAd正在将其大小调整为全屏,以便在显示iAd时显示广告。

相关问题