iAd关闭后留下白屏问题

3
我在我的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;
}
}

你能帮我解决这个问题吗?https://dev59.com/KVfUa4cB1Zd3GeqPEAyx - ajay
3个回答

4

最终我自己解决了这个问题。原来ADBannerView的父视图必须是全屏视图。在我的情况下,我把AdBannerView添加到了大小为320x50的adView中。当我将其父视图更改为全屏视图时,一切正常工作了。我不确定这是否是iAd中的一个错误,但肯定有些棘手。


1

嘿,David!我知道你的意思,我也在使用自己的AdvertisementViewController来调用不同的广告网络。

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

只需要这样做:

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

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

}

因此,外部视图容器(self.view)被调整为其原始大小。当显示iAd时,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];
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接