如何在某个SKScene上显示iAd并将其隐藏在另一个SKScene上 [英] How to show iAd on a certain SKScene and hide it on the other one
问题描述
我正在制作一个简单的游戏,我想在游戏上方屏幕"的顶部添加一个iAd
.我可以将其添加到UIViewController
,但是随后它会在播放时显示,这是我不想要的.
I'm making a simple game and I would like to add an iAd
at the top of the Game Over Screen. I could add it on to the UIViewController
, but then it would show up while playing, which is something I don't want.
是否有办法使iAd
仅出现在某个SKScene
上?感谢您的所有帮助!
Is there a way to make the iAd
appear only on a certain SKScene
? Thanks for all your help!
推荐答案
最干净的解决方案是声明并实现一个协议,以使UIViewController
知道它应该隐藏广告.
The most clean solution is to declare and implement a protocol to let the UIViewController
know that it should hide the ad.
@protocol MySceneDelegate <NSObject>
- (void)hideAd;
- (void)showAd;
@end
@interface MyScene : SKScene
@property (weak) id <MySceneDelegate> delegate;
@end
显示场景的
视图控制器应实现hideAd
方法,并将其自身设置为场景的委托.示例:
View controller that shows the scene should implement a hideAd
method and set itself as a delegate of the scene. Example:
- (void)viewDidLoad
{
[super viewDidLoad];
// Configure the view, etc.
...
// Set the delegate
[scene setDelegate:self];
// Present the scene.
[skView presentScene:scene];
}
然后在您不想展示广告的场景中,可以调用设置为委托的视图控制器的hideAd
方法:
Then in the scene you don't want to show an ad, you can call the hideAd
method of the view controller which was set as a delegate:
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
/* Called when a touch begins */
if ([_delegate respondsToSelector:@selector(hideAd)])
{
[_delegate performSelector:@selector(hideAd)];
}
}
您可以告诉视图控制器以相同的方式展示广告. 希望对您有所帮助.
You can tell the view controller to show the ad in the same way. Hope it helps.
这篇关于如何在某个SKScene上显示iAd并将其隐藏在另一个SKScene上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!