xcode 4.3 - storyboard - iAd keeps moving

六月ゝ 毕业季﹏ 提交于 2019-12-18 12:42:26

问题


I have added iAd to my iphone app to be at the top of my app. originally I place it at x=0 and y=-50 so that it comes from off the screen. I use the following code for it in my .m :

    - (void)bannerView:(ADBannerView *)abanner didFailToReceiveAdWithError:(NSError *)error
{
    if (self.bannerIsVisible)
    {
        [UIView beginAnimations:@"animateAdBannerOff" context:NULL];
        // Assumes the banner view is placed at the bottom of the screen.
        banner.frame = CGRectOffset(banner.frame, 0, banner.frame.size.height);
        [UIView commitAnimations];
        self.bannerIsVisible = NO;
    }
}

- (void)bannerViewDidLoadAd:(ADBannerView *)abanner
{
    if (!self.bannerIsVisible)
    {
        [UIView beginAnimations:@"animateAdBannerOn" context:NULL];
        // Assumes the banner view is just off the bottom of the screen.
        banner.frame = CGRectOffset(banner.frame, 0, banner.frame.size.height);
        [UIView commitAnimations];
        self.bannerIsVisible = YES;
    }
}

When my app launch iAd get displayed at the top without any problem. but when I open another app and come back to it (without killing it so my app is running in the background) the banner moves another 50 pixel down

any idea?


回答1:


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;
    }
}


来源:https://stackoverflow.com/questions/9820872/xcode-4-3-storyboard-iad-keeps-moving

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!