Skip to content

Instantly share code, notes, and snippets.

@ellneal
Created July 14, 2011 13:56
Show Gist options
  • Save ellneal/1082499 to your computer and use it in GitHub Desktop.
Save ellneal/1082499 to your computer and use it in GitHub Desktop.
ADBannerView Show/Hide : Add this to your snippets library for any time you're working with iAd. Simply drop these two methods in your UIViewController subclass, and call them from ADBannerViewDelegate methods, or anywhere else.
#pragma mark - ADBannerView Show/Hide
- (void)showBannerView:(ADBannerView *)bannerView animated:(BOOL)animated {
if ([bannerView superview] != nil)
return;
UIView *bannerSuperview = <#banner superview#>;
UIView *contentView = <#content view#>;
CGRect contentFrame = contentView.frame;
CGRect bannerFrame = bannerView.frame;
bannerFrame.origin.y = CGRectGetMaxY(contentFrame);
bannerView.frame = bannerFrame;
[bannerSuperview addSubview:bannerView];
contentFrame.size.height -= bannerFrame.size.height;
bannerFrame.origin.y -= bannerFrame.size.height;
void (^moveBannerView)(void) = ^{
contentView.frame = contentFrame;
bannerView.frame = bannerFrame;
};
if (animated) {
[UIView animateWithDuration:0.3 animations:moveBannerView];
}
else {
moveBannerView();
}
}
- (void)hideBannerView:(ADBannerView *)bannerView animated:(BOOL)animated {
if ([bannerView superview] == nil)
return;
UIView *contentView = <#content view#>;
CGRect contentFrame = contentView.frame;
CGRect bannerFrame = bannerView.frame;
bannerFrame.origin.y = CGRectGetMaxY(contentFrame) + bannerFrame.size.height;
contentFrame.size.height += bannerFrame.size.height;
void (^moveBannerView)(void) = ^ {
contentView.frame = contentFrame;
bannerView.frame = bannerFrame;
};
if (animated) {
[UIView animateWithDuration:0.3 animations:moveBannerView completion:^(BOOL finished) {
[bannerView removeFromSuperview];
}];
}
else {
moveBannerView();
[bannerView removeFromSuperview];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment