【问题标题】:iAd left white blank screen after closediAd关闭后留下白色空白屏幕
【发布时间】:2010-07-02 15:14:25
【问题描述】:

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

【问题讨论】:

标签: iphone ios4 iad


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    横幅结束后,它会自行移动到屏幕顶部,即使这意味着 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];
    }
    

    【讨论】:

      【解决方案3】:

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

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

      只需这样做:

      -(void) bannerViewActionDidFinish:(ADBannerView *)inBanner {
      
      [self.view setFrame:CGRectMake(0.0f, 0.0f, 320.0f, 50.0f)];
      
      }
      

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

      【讨论】:

        猜你喜欢
        • 2014-01-13
        • 2016-05-08
        • 1970-01-01
        • 2018-03-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-08-18
        • 1970-01-01
        相关资源
        最近更新 更多