Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1).h
- #import "GADBannerViewDelegate.h"
- @class GADBannerView, GADRequest;
- <GADBannerViewDelegate>
- //admob
- @private
- GADBannerView *bannerView_;
- BOOL isAdPositionAtTop_;
- //admob
- - (GADRequest *)createRequest;
- @property(strong,nonatomic)GADBannerView *bannerView;
- 2).m
- //admob
- #import "GADBannerView.h"
- #import "GADRequest.h"
- #import "AppID.h"
- #pragma mark - IntroLayer
- #define kHighScoreKey @"com.theme5hq"
- //admob
- typedef enum _bannerType
- {
- kBanner_Portrait_Top,
- kBanner_Portrait_Bottom,
- kBanner_Landscape_Top,
- kBanner_Landscape_Bottom,
- }CocosBannerType;
- #define BANNER_TYPE kBanner_Landscape_Bottom //change this on need basis
- //end admob
- at interface
- CocosBannerType mBannerType;
- float on_x, on_y, off_x, off_y;
- @synthesize bannerView = bannerView_;
- // admob
- -(void)createAdmobAds
- {
- mBannerType = BANNER_TYPE;
- AppController *app = (AppController*)[[UIApplication sharedApplication] delegate];
- // Create a view of the standard size at the bottom of the screen.
- // Available AdSize constants are explained in GADAdSize.h.
- if(mBannerType <= kBanner_Portrait_Bottom)
- bannerView_ = [[GADBannerView alloc] initWithAdSize:kGADAdSizeSmartBannerPortrait];
- else
- bannerView_ = [[GADBannerView alloc] initWithAdSize:kGADAdSizeSmartBannerLandscape];
- // Specify the ad's "unit identifier." This is your AdMob Publisher ID.
- bannerView_.adUnitID = MyUnitId;
- // Let the runtime know which UIViewController to restore after taking
- // the user wherever the ad goes and add it to the view hierarchy.
- bannerView_.rootViewController = app.navController;
- [app.navController.view addSubview:bannerView_];
- // Initiate a generic request to load it with an ad.
- [bannerView_ loadRequest:[GADRequest request]];
- CGSize s = [[CCDirector sharedDirector] winSize];
- CGRect frame = bannerView_.frame;
- off_x = 0.0f;
- on_x = 0.0f;
- switch (mBannerType)
- {
- case kBanner_Portrait_Top:
- {
- off_y = -frame.size.height;
- on_y = 0.0f;
- }
- break;
- case kBanner_Portrait_Bottom:
- {
- off_y = s.height;
- on_y = s.height-frame.size.height;
- }
- break;
- case kBanner_Landscape_Top:
- {
- off_y = -frame.size.height;
- on_y = 0.0f;
- }
- break;
- case kBanner_Landscape_Bottom:
- {
- off_y = s.height;
- on_y = s.height-frame.size.height;
- }
- break;
- default:
- break;
- }
- frame.origin.y = off_y;
- frame.origin.x = off_x;
- bannerView_.frame = frame;
- [UIView beginAnimations:nil context:nil];
- [UIView setAnimationDuration:0.2];
- [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
- frame = bannerView_.frame;
- frame.origin.x = on_x;
- frame.origin.y = on_y;
- bannerView_.frame = frame;
- [UIView commitAnimations];
- }
- -(void)showBannerView
- {
- if (bannerView_)
- {
- [UIView animateWithDuration:0.2
- delay:0.1
- options: UIViewAnimationCurveEaseOut
- animations:^
- {
- CGRect frame = bannerView_.frame;
- frame.origin.y = on_y;
- frame.origin.x = on_x;
- bannerView_.frame = frame;
- }
- completion:^(BOOL finished)
- {
- }];
- }
- }
- -(void)hideBannerView
- {
- if (bannerView_)
- {
- [UIView animateWithDuration:0.2
- delay:0.1
- options: UIViewAnimationCurveEaseOut
- animations:^
- {
- CGRect frame = bannerView_.frame;
- frame.origin.y = off_y;
- frame.origin.x = off_x;
- }
- completion:^(BOOL finished)
- {
- }];
- }
- }
- -(void)dismissAdView
- {
- if (bannerView_)
- {
- [UIView animateWithDuration:0.2
- delay:0.1
- options: UIViewAnimationCurveEaseOut
- animations:^
- {
- CGRect frame = bannerView_.frame;
- frame.origin.y = off_y;
- frame.origin.x = off_x;
- bannerView_.frame = frame;
- }
- completion:^(BOOL finished)
- {
- [bannerView_ setDelegate:nil];
- [bannerView_ removeFromSuperview];
- bannerView_ = nil;
- }];
- }
- }
- //end admob
- - (void) dealloc
- {
- //[viewController release];
- bannerView_.delegate = nil;
- [bannerView_ release];
- [super dealloc];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement