Ios 在精灵套件场景中隐藏iAd
我已使用以下代码将IAD添加到我的精灵套件游戏中: 在viewController.h文件中Ios 在精灵套件场景中隐藏iAd,ios,objective-c,sprite-kit,Ios,Objective C,Sprite Kit,我已使用以下代码将IAD添加到我的精灵套件游戏中: 在viewController.h文件中 @property (strong, nonatomic) IBOutlet ADBannerView * adBannerView; 在viewController.m文件中 - (void)viewWillLayoutSubviews { [super viewWillLayoutSubviews]; // Configure the view. SKView * skV
@property (strong, nonatomic) IBOutlet ADBannerView * adBannerView;
在viewController.m文件中
- (void)viewWillLayoutSubviews
{
[super viewWillLayoutSubviews];
// Configure the view.
SKView * skView = (SKView *)self.view;
if (!skView.scene) {
// Create and configure the scene.
SKScene * scene = [MenuScene sceneWithSize:skView.bounds.size];
scene.scaleMode = SKSceneScaleModeAspectFill;
_adBannerView = [[ADBannerView alloc] initWithFrame:CGRectZero];
_adBannerView.delegate = self;
[_adBannerView setFrame:CGRectMake(0, 0, 460, 320)];
[self.view addSubview:_adBannerView];
// Present the scene.
[skView presentScene:scene];
}
}
这显示了每个场景中的iAd。有没有办法在某些场景中隐藏iAd
苹果的iAd编程指南上说:
仅当您打算向用户显示横幅视图时,才创建横幅视图。否则,它可能会循环浏览广告并耗尽应用程序的可用广告列表
这在场景中是完全可能的吗?好吧,在您的特定场景中,请按照下面链接中有关此问题的苹果指南(与您的问题位置相同),查看“横幅视图最佳实践”部分:
总之,他们说:“从视图层次结构中删除横幅视图,将其委托设置为
nil
”最干净的解决方案是声明并实现一个协议,让UIViewController
从场景中知道它应该隐藏广告
@protocol MySceneDelegate <NSObject>
- (void)hideAd;
@end
@interface MyScene : SKScene
@property (weak) id <MySceneDelegate> delegate;
@end
然后在场景中,可以调用设置为代理的视图控制器的hideAd
方法:
if ([_delegate respondsToSelector:@selector(closeScene)])
{
[_delegate performSelector:@selector(hideAd)];
}
并删除hideAd
方法中的横幅
要隐藏横幅视图,您应该:
调整横幅视图框架的大小以使其脱离屏幕调整内容大小
视图的框架覆盖最初承载横幅的空间
希望有帮助。是的,有一种方法可以在某些场景中隐藏iAd
- (void)viewDidLoad
{
[super viewDidLoad];
//Add view controller as observer
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleNotification:) name:@"hideAd" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleNotification:) name:@"showAd" object:nil];
// Configure the view.
SKView * skView = (SKView *)self.view;
skView.showsFPS = NO;
skView.showsNodeCount = NO;
// Create and configure the scene.
SKScene * scene = [MyScene sceneWithSize:skView.bounds.size];
scene.scaleMode = SKSceneScaleModeAspectFill;
// Present the scene.
[skView presentScene:scene];
self.canDisplayBannerAds = YES;
adView = [[ADBannerView alloc] initWithFrame:CGRectZero];
adView.frame = CGRectOffset(adView.frame, 0, 0.0f);
adView.delegate=self;
[self.view addSubview:adView];
self.bannerIsVisible=NO;
}
//Handle Notification
- (void)handleNotification:(NSNotification *)notification
{
if ([notification.name isEqualToString:@"hideAd"]) {
[self hidesBanner];
} else if ([notification.name isEqualToString:@"showAd"]) {
[self showBanner];
}
}
在你想隐藏横幅的场景中
[[NSNotificationCenter defaultCenter] postNotificationName:@"showAd" object:nil];
//Sends message to viewcontroller to show ad.
[[NSNotificationCenter defaultCenter] postNotificationName:@"hideAd" object:nil];
//Sends message to viewcontroller to hide ad.
[[NSNotificationCenter defaultCenter] postNotificationName:@"showAd" object:nil];
//Sends message to viewcontroller to show ad.
[[NSNotificationCenter defaultCenter] postNotificationName:@"hideAd" object:nil];
//Sends message to viewcontroller to hide ad.