Created
July 14, 2011 13:56
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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