我正在使用Xcode和SpriteKit制作一个游戏,我正在使用admob集成广告,所有的代码都可以用于横幅广告,并且能够让间隙广告也能工作。我的问题是告诉游戏何时显示间隙广告。广告在GameViewController中,但我需要从GameScene.swift调用showAd()方法,如何从GameScene中的GameViewController调用函数。任何帮助都是非常感谢的,谢谢,扎克。
发布于 2016-10-20 20:45:08
在GameViewController中,在viewWillLayoutSubviews中设置一个通知观察者,如下所示:
override func viewWillLayoutSubviews() {
NotificationCenter.default.addObserver(self, selector: #selector(self.showAd), name: NSNotification.Name(rawValue: "showAd"), object: nil)
}然后在您的GameScene中,当您希望运行GameViewController中的函数时调用它:
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "showAd"), object: nil)请记住,您需要在GameViewController中调用一个函数。showAd只是一个占位符,用于您想要在GameViewController中运行的任何函数。
希望这能帮上忙!
https://stackoverflow.com/questions/40145907
复制相似问题