How to properly hide these ad banners?

后端 未结 1 1949
一生所求
一生所求 2021-01-03 12:50

(Sprite Kit Game) I want my ad banners to be hidden during gameplay. I\'ve set up my project to contain both iAd and AdMob advertisement banners. Prior to adding in the AdMo

相关标签:
1条回答
  • 2021-01-03 12:54

    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];
    
    }
    
    0 讨论(0)
提交回复
热议问题