Skip to content

Commit

Permalink
animate ads
Browse files Browse the repository at this point in the history
  • Loading branch information
ianmaclarty committed Dec 26, 2016
1 parent 6c564b8 commit ea5c138
Showing 1 changed file with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions src/am_backend_ios.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,24 @@ static void ios_become_active() {
}
}

static void hide_banner() {
[UIView animateWithDuration:0.5
animations:^ { banner_ad.frame = CGRectMake(0.0, -banner_ad.frame.size.height,
banner_ad.frame.size.width,
banner_ad.frame.size.height);
}
completion:^(BOOL finished){ banner_ad.hidden = YES; }];
}

static void show_banner() {
banner_ad.hidden = NO;
[UIView animateWithDuration:0.5 animations:^ {
banner_ad.frame = CGRectMake(0.0, 0.0,
banner_ad.frame.size.width,
banner_ad.frame.size.height);
}];
}

static CMMotionManager *motionManager = nil;

@interface AMViewController : GLKViewController { }
Expand Down Expand Up @@ -777,15 +795,15 @@ static id banner_delegate = nil;
{
banner_ad_filled = true;
if (banner_ad_want_visible) {
banner_ad.hidden = NO;
show_banner();
}
}

- (void)adView:(nonnull GADBannerView *)bannerView
didFailToReceiveAdWithError:(nonnull GADRequestError *)error
{
banner_ad_filled = false;
banner_ad.hidden = YES;
//banner_ad.hidden = YES;
}

- (void)dealloc
Expand Down Expand Up @@ -1152,6 +1170,9 @@ static int init_google_banner_ad(lua_State *L) {
if (unitid == NULL) return luaL_error(L, "expecting a string unitid argument");
banner_ad = [[GADBannerView alloc] initWithAdSize:kGADAdSizeSmartBannerPortrait];
banner_ad.hidden = YES;
banner_ad.frame = CGRectMake(0.0, -banner_ad.frame.size.height,
banner_ad.frame.size.width,
banner_ad.frame.size.height);
banner_ad.adUnitID = [NSString stringWithUTF8String:unitid];
banner_ad.rootViewController = ios_view_controller;
banner_ad.delegate = banner_delegate;
Expand All @@ -1165,9 +1186,9 @@ static int set_google_banner_ad_visible(lua_State *L) {
bool vis = lua_toboolean(L, 1) ? true : false;
banner_ad_want_visible = vis;
if (vis && banner_ad_filled) {
banner_ad.hidden = NO;
show_banner();
} else if (!vis) {
banner_ad.hidden = YES;
hide_banner();
}
return 0;
}
Expand All @@ -1181,7 +1202,7 @@ static int is_google_banner_ad_visible(lua_State *L) {
static int request_google_banner_ad(lua_State *L) {
if (banner_ad == nil) return luaL_error(L, "please initialse ads first");
[banner_ad loadRequest:[GADRequest request]];
banner_ad.hidden = YES;
hide_banner();
return 0;
}

Expand Down

0 comments on commit ea5c138

Please sign in to comment.