How to properly hide these ad banners?

纵饮孤独 提交于 2019-11-30 16:20:40

You could use a BOOL as a switch to show either appleAd or googleBanner, or none as you might want:

In your .h file:

BOOL isAppleAd;
BOOL isGoogleAd;

Then do something like this:

- (void)showsBanner {

    if (isAppleAd == YES) {
        [self appleAd];
    }
    if (isGoogleAd == YES) {
        [self googleAd];
    }
    else {
        [self hideBothBanners];
    }

}

- (void)appleAd {

        if (isAppleAd == YES) {

        NSLog(@"Showing Apple Banner");

        //googleAd OFF
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration:0];
        [googleBanner_ setAlpha:0];
        [UIView commitAnimations];

        // iAd ON
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration:1.0];
        [appleAd setAlpha:1.0];
        [UIView commitAnimations];

        // switch off AppleAd to use as switch
        isAppleAd = NO;
        isGoogleAd = YES;

    } else {
        // do something else
        return;
    }

}

- (void)googleAd {

    if (isGoogleAd == YES) {

        NSLog(@"Showing Google Banner");

        // iAd OFF
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration:0];
        [appleAd setAlpha:0];
        [UIView commitAnimations];

        // googleAd ON
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration:1.0];
        [googleBanner_ setAlpha:1.0];
        [UIView commitAnimations];

        // switch off GoogleAd to use as switch
        isGoogleAd = NO;
        isAppleAd = YES;

    } else {
        // do something else
        return;
    }

}

- (void)hideBothBanners {

        NSLog(@"Hiding Both Banners");

        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration:0];
        [appleAd setAlpha:0];
        [googleBanner_ setAlpha:0]
        [UIView commitAnimations];

}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!