iAds没有隐藏

时间:2012-10-23 09:22:43

标签: iphone hide iad

我在屏幕底部有ADBannerView的IBOutlet,当它显示白屏(无法​​加载广告)时我不会隐藏它。

我有这段代码,但它无效:

- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
    [UIView beginAnimations:@"showAd" context:nil];

    CGRect adBannerViewFrame = [bannerView frame];
    adBannerViewFrame.origin.x = 160;
    adBannerViewFrame.origin.y = 523;

    bannerView.frame = adBannerViewFrame;

    [UIView commitAnimations];
}

- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
    [UIView beginAnimations:@"hideAd" context:nil];

    CGRect adBannerViewFrame = [bannerView frame];
    adBannerViewFrame.origin.x = 0;
    adBannerViewFrame.origin.y = 0;

    bannerView.frame = adBannerViewFrame;

    [UIView commitAnimations];
}

你能帮助我吗,我在过去两个小时里一直在努力......:/

1 个答案:

答案 0 :(得分:0)

你应该尝试这样的事情(这是来自现场项目)。 iAd横幅位于屏幕的底部,当它变得不可见时会下降,当它必须可见时它会回来。

_isiADBannerVisible只是一个简单的Boolean变量。

- (void)bannerViewDidLoadAd:(ADBannerView *)banner {
    if (_isiADBannerVisible == false) {
         _isiADBannerVisible = true;

         [UIView animateWithDuration:0.5f delay:0.f options:UIViewAnimationCurveEaseInOut animations:^{
             [banner setFrame:CGRectOffset(banner.frame, 0.f, -50.f)];
         } completion:nil];
    }
}

- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error {
    if (_isiADBannerVisible == true) {
         _isiADBannerVisible = false;

         [UIView animateWithDuration:0.5f delay:0.f options:UIViewAnimationCurveEaseInOut animations:^{
             [banner setFrame:CGRectOffset(banner.frame, 0.f, +50.f)];
         } completion:nil];

    }
}