I was wondering the same thing for a while. I believe I've come up with a trick, because I don't get any warnings when I do this.
Here's the view hierarchy I have:
UIView (same size as your iAd)
|_ iAd (make sure to pin the height and width if using iOS 6 auto layout)
|_ UIView (I create this dynamically and use it's presence to determine whether I should show or hide the iAd from the delegate)
The code below manipulates the auto layout constraints I have setup in Interface Builder. If you're not using auto layout, then you'll have to change what triggers the animation.
- (void)hideAdBanner {
if (!__adBannerReverseSideView) {
__adBannerReverseSideView = [[UIView alloc] initWithFrame:__adBannerView.frame];
__adBannerReverseSideView.backgroundColor = [UIColor blackColor];
__adBannerReverseSideView.opaque = YES;
[UIView transitionFromView:__adBannerView toView:__adBannerReverseSideView duration:0.3
options:UIViewAnimationOptionTransitionFlipFromBottom | UIViewAnimationOptionCurveEaseInOut
completion:^(BOOL finished) {
[UIView animateWithDuration:0.3 animations:^{
__adBannerBottomConstraint.constant += __adBannerContainerView.frame.size.height;
[self.view layoutIfNeeded];
}];
}];
}
}
- (void)showAdBanner {
if (__adBannerReverseSideView) {
[UIView animateWithDuration:0.3
animations:^{
__adBannerBottomConstraint.constant -= __adBannerContainerView.frame.size.height;
[self.view layoutIfNeeded];
}
completion:^(BOOL finished) {
[__adBannerView setNeedsLayout];
[UIView transitionFromView:__adBannerReverseSideView toView:__adBannerView duration:0.3
options:UIViewAnimationOptionTransitionFlipFromTop | UIViewAnimationOptionCurveEaseInOut
completion:^(BOOL finished) {
[__adBannerReverseSideView removeFromSuperview];
__adBannerReverseSideView = nil;
}];
}];
}
}
The hide code transitions the AD Banner to the "reverse" view. You can change the animation types with the options parameter.
The show code transitions the other way (from "reverse" view to AD Banner). All of the animation happens with the superview which is the same size as the AD Banner. This way your entire view won't animate.
Leave the iAd in the superview, don't remove it. This may be the root cause of the warning, but I'm not sure.
Then here are my AD Delegate methods:
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error {
[self hideAdBanner];
}
- (void)bannerViewDidLoadAd:(ADBannerView *)banner {
[self showAdBanner];
}
Don't kill me for not checking the error variable. I haven't gotten around to writing that code just yet.
With regard to pinning the height and width of the ad banner view in iOS 6 auto layout, if you don't when the iAd animates back into place, the upper left hand corner will shift down and to the right by half the height and width of its superview every time it comes back into view. :) Fun stuff.