Xcode 4.3 - storyboard - iAd keeps moving

I added an iAd to my iphone app to be at the top of my app. I initially put it at x = 0 and y = -50, so that it comes from 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 launch of the iAd application will be displayed on top without any problems. but when I open another application and return to it (without killing it, so that my application runs in the background), the banner moves another 50 pixels down enter image description here

any idea?

+2
source share
1 answer

In both cases, you add 50.0px to banner.frame.origin.y .

In any case: even if you subtract 50.px in didFailToReceiveAdWithError: it may happen that didFailToReceiveAdWithError: is called several times in and your code can move the banner higher and higher (-50.0, -100.0, -150.0 ...) .

So it’s better to rigidly set hidden and visible positions, rather than calculate them.

Try the following:

 - (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; } } 
+2
source

All Articles