首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >隐藏iAd横幅SKScene

隐藏iAd横幅SKScene
EN

Stack Overflow用户
提问于 2015-01-26 18:53:41
回答 1查看 121关注 0票数 0

大家好,你们认为我应该在句柄通知(hideAd,showAd)中使用什么来显示和隐藏我的项目中的iAd横幅,下面是我用来显示iAd横幅`#import "GameViewController.h“的内容。

导入"GameScene.h“

@接口GameViewController(){

代码语言:javascript
复制
bool adOnTop;
bool iadsBannerIsVisible;
 ADBannerView* theBanner;

}

@end

代码语言:javascript
复制
@implementation GameViewController

- (void)viewDidLoad

{

代码语言:javascript
复制
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleNotification:) name:@"hideAd" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleNotification:) name:@"showAd" object:nil];


[super viewDidLoad];

// Configure the view.
SKView * skView = (SKView *)self.view;
skView.showsFPS = YES;
skView.showsNodeCount = YES;
skView.multipleTouchEnabled = YES;
/* Sprite Kit applies additional optimizations to improve rendering performance */
skView.ignoresSiblingOrder = YES;

// Create and configure the scene.
GameScene *scene = [GameScene sceneWithSize:skView.bounds.size];
scene.scaleMode = SKSceneScaleModeAspectFit;

// Present the scene.
[skView presentScene:scene];

[self showThinBanner];

}

代码语言:javascript
复制
-(void) showThinBanner {
iadsBannerIsVisible = YES;
theBanner = [[ADBannerView alloc] initWithFrame:CGRectZero];
[theBanner setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
theBanner.delegate = self;


[self.view addSubview:theBanner];

}

代码语言:javascript
复制
- (BOOL)bannerViewActionShouldBegin:(ADBannerView *)banner willLeaveApplication:(BOOL)willLeave {
NSLog(@"Banner view is beginning an ad action");
BOOL shouldExecuteAction = YES; // your app implements this method

if (!willLeave && shouldExecuteAction){
    // insert code here to suspend any services that might conflict with the advertisement, for example, you might pause the game with an NSNotification like this...
    [[NSNotificationCenter defaultCenter] postNotificationName:@"PauseScene" object:nil]; //optional
}
return shouldExecuteAction;

}

代码语言:javascript
复制
-(void) bannerViewActionDidFinish:(ADBannerView *)banner {
NSLog(@"banner is done being fullscreen");
//Unpause the game if you paused it previously.
[[NSNotificationCenter defaultCenter] postNotificationName:@"UnPauseScene" object:nil]; //optional

}

代码语言:javascript
复制
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
    

    
    if (iadsBannerIsVisible == YES) {
        
        [UIView beginAnimations:@"animateAdBannerOff" context:NULL];
        // Assumes the banner view is placed at the bottom of the screen.
         banner.frame = CGRectOffset(banner.frame, 0, banner.frame.size.height);
        [UIView commitAnimations];
        iadsBannerIsVisible = NO;
        
        NSLog(@"banner unavailable");
    }
    }



- (void)handleNotification:(NSNotification *)notification


{ 
if ([notification.name isEqualToString:@"hideAd"])
    {
         // hide your banner;
}else if ([notification.name isEqualToString:@"showAd"]) 
    {
         // show your banner
}


}
EN

回答 1

Stack Overflow用户

发布于 2015-01-26 20:28:48

已解决

代码语言:javascript
复制
- (void)handleNotification:(NSNotification *)notification
{
if ([notification.name isEqualToString:@"hideAd"])
{
    // hide your banner;



    [theBanner removeFromSuperview];




}else if ([notification.name isEqualToString:@"showAd"])
{
    // show your banner

    [self.view addSubview:theBanner];


}
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28148747

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档