xcode 4.3 - storyboard - iAd keeps moving

試著忘記壹切 提交于 2019-11-30 07:45:39

You are adding 50.0px to banner.frame.origin.y in both cases.

Anyway: even if you'd be substracting 50.px in didFailToReceiveAdWithError: it could happen that didFailToReceiveAdWithError: would get called multiple times in a row and your code could move the banner higher and higher up (-50.0,-100.0,-150.0...).

So it's better to hardcode the hidden & visible positions instead of calculating it.

Try this:

- (void)bannerView:(ADBannerView *)abanner didFailToReceiveAdWithError:(NSError *)error
{
    if (self.bannerIsVisible)
    {
        [UIView beginAnimations:@"animateAdBannerOff" context:NULL];
        banner.frame = CGRectMake(0.0,-50.0,banner.frame.size.width,banner.frame.size.height);
        [UIView commitAnimations];
        self.bannerIsVisible = NO;
    }
}

- (void)bannerViewDidLoadAd:(ADBannerView *)abanner
{
    if (!self.bannerIsVisible)
    {
        [UIView beginAnimations:@"animateAdBannerOn" context:NULL];
        banner.frame = CGRectMake(0.0,0.0,banner.frame.size.width,banner.frame.size.height);
        [UIView commitAnimations];
        self.bannerIsVisible = YES;
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!