[英]How to show iAd on a certain SKScene and hide it on the other one
I'm making a simple game and I would like to add an iAd
at the top of the Game Over Screen. 我正在制作一个简单的游戏,我想在“屏幕游戏”的顶部添加一个iAd
。 I could add it on to the UIViewController
, but then it would show up while playing, which is something I don't want. 我可以将其添加到UIViewController
,但是随后它会在播放时显示,这是我不想要的。
Is there a way to make the iAd
appear only on a certain SKScene
? 有没有办法让iAd
仅出现在某个SKScene
? Thanks for all your help! 感谢你的帮助!
The most clean solution is to declare and implement a protocol to let the UIViewController
know that it should hide the ad. 最干净的解决方案是声明并实现协议,以使UIViewController
知道应隐藏广告。
@protocol MySceneDelegate <NSObject>
- (void)hideAd;
- (void)showAd;
@end
@interface MyScene : SKScene
@property (weak) id <MySceneDelegate> delegate;
@end
View controller that shows the scene should implement a hideAd
method and set itself as a delegate of the scene. 显示场景的视图控制器应实现hideAd
方法,并将其自身设置为场景的委托。 Example: 例:
- (void)viewDidLoad
{
[super viewDidLoad];
// Configure the view, etc.
...
// Set the delegate
[scene setDelegate:self];
// Present the scene.
[skView presentScene:scene];
}
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: 然后,在您不想展示广告的场景中,可以调用设置为委托的视图控制器的hideAd
方法:
-(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. 希望能帮助到你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.