Swift 关闭iAD横幅会导致当前场景发生更改
我实现了Swift 关闭iAD横幅会导致当前场景发生更改,swift,iad,Swift,Iad,我实现了iAD,它在屏幕底部显示一个横幅。我在菜单类和游戏场景类中调用函数showsAD(),以显示横幅游戏场景是所有游戏发生的地方。如果我在游戏场景中单击iAd横幅,出于某种原因,它会自动将场景切换回菜单。在一些在线资源中,这是我用来显示iAd横幅的代码,它位于GameViewContorller: class GameViewController: UIViewController, ADBannerViewDelegate { var SH = UIScreen.mainScree
iAD
,它在屏幕底部显示一个横幅。我在菜单
类和游戏场景
类中调用函数showsAD()
,以显示横幅<代码>游戏场景是所有游戏发生的地方。如果我在游戏场景
中单击iAd横幅
,出于某种原因,它会自动将场景切换回菜单
。在一些在线资源中,这是我用来显示iAd横幅的代码,它位于GameViewContorller
:
class GameViewController: UIViewController, ADBannerViewDelegate {
var SH = UIScreen.mainScreen().bounds.height
let transition = SKTransition.fadeWithDuration(1)
var UIiAd: ADBannerView = ADBannerView()
override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()
NSNotificationCenter.defaultCenter().addObserver(self, selector: "hideBannerAd", name: "hideadsID", object: nil)
NSNotificationCenter.defaultCenter().addObserver(self, selector: "showBannerAd", name: "showadsID", object: nil)
self.UIiAd.hidden = true
self.UIiAd.alpha = 0
}
override func viewWillAppear(animated: Bool) {
let BV = UIiAd.bounds.height
UIiAd.delegate = self
UIiAd.frame = CGRectMake(0, SH + BV, 0, 0)
self.view.addSubview(UIiAd)
}
override func viewWillDisappear(animated: Bool) {
UIiAd.delegate = nil
UIiAd.removeFromSuperview()
}
func bannerViewDidLoadAd(banner: ADBannerView!) {
_ = UIiAd.bounds.height
UIView.beginAnimations(nil, context: nil)
UIView.setAnimationDuration(0.01) // Time it takes the animation to complete
UIiAd.alpha = 1 // Fade in the animation
UIView.commitAnimations()
}
func bannerView(banner: ADBannerView!, didFailToReceiveAdWithError error: NSError!) {
UIView.beginAnimations(nil, context: nil)
UIView.setAnimationDuration(0.01)
UIiAd.alpha = 0
UIView.commitAnimations()
}
func showBannerAd() {
UIiAd.hidden = false
let BV = UIiAd.bounds.height
UIView.beginAnimations(nil, context: nil)
UIView.setAnimationDuration(0.01) // Time it takes the animation to complete
UIiAd.frame = CGRectMake(0, SH - BV, 0, 0) // End position of the animation
UIView.commitAnimations()
}
func hideBannerAd() {
UIiAd.hidden = true
let BV = UIiAd.bounds.height
UIView.beginAnimations(nil, context: nil)
UIView.setAnimationDuration(0.01) // Time it takes the animation to complete
UIiAd.frame = CGRectMake(0, SH + BV, 0, 0) // End position of the animation
UIView.commitAnimations()
}
func showAds(){
NSNotificationCenter.defaultCenter().postNotificationName("showadsID", object: nil)
}
然后在游戏场景
和菜单
类中,这是我用来显示iAD横幅
:
class GameViewController: UIViewController, ADBannerViewDelegate {
var SH = UIScreen.mainScreen().bounds.height
let transition = SKTransition.fadeWithDuration(1)
var UIiAd: ADBannerView = ADBannerView()
override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()
NSNotificationCenter.defaultCenter().addObserver(self, selector: "hideBannerAd", name: "hideadsID", object: nil)
NSNotificationCenter.defaultCenter().addObserver(self, selector: "showBannerAd", name: "showadsID", object: nil)
self.UIiAd.hidden = true
self.UIiAd.alpha = 0
}
override func viewWillAppear(animated: Bool) {
let BV = UIiAd.bounds.height
UIiAd.delegate = self
UIiAd.frame = CGRectMake(0, SH + BV, 0, 0)
self.view.addSubview(UIiAd)
}
override func viewWillDisappear(animated: Bool) {
UIiAd.delegate = nil
UIiAd.removeFromSuperview()
}
func bannerViewDidLoadAd(banner: ADBannerView!) {
_ = UIiAd.bounds.height
UIView.beginAnimations(nil, context: nil)
UIView.setAnimationDuration(0.01) // Time it takes the animation to complete
UIiAd.alpha = 1 // Fade in the animation
UIView.commitAnimations()
}
func bannerView(banner: ADBannerView!, didFailToReceiveAdWithError error: NSError!) {
UIView.beginAnimations(nil, context: nil)
UIView.setAnimationDuration(0.01)
UIiAd.alpha = 0
UIView.commitAnimations()
}
func showBannerAd() {
UIiAd.hidden = false
let BV = UIiAd.bounds.height
UIView.beginAnimations(nil, context: nil)
UIView.setAnimationDuration(0.01) // Time it takes the animation to complete
UIiAd.frame = CGRectMake(0, SH - BV, 0, 0) // End position of the animation
UIView.commitAnimations()
}
func hideBannerAd() {
UIiAd.hidden = true
let BV = UIiAd.bounds.height
UIView.beginAnimations(nil, context: nil)
UIView.setAnimationDuration(0.01) // Time it takes the animation to complete
UIiAd.frame = CGRectMake(0, SH + BV, 0, 0) // End position of the animation
UIView.commitAnimations()
}
func showAds(){
NSNotificationCenter.defaultCenter().postNotificationName("showadsID", object: nil)
}
我试着停下来,但没有成功。代码如下:
func bannerViewActionShouldBegin(banner: ADBannerView!, willLeaveApplication willLeave: Bool) -> Bool {
print("Clicked")
iAdBanner.delegate = self
// If you want to pause game scene:
let skView: SKView = self.view as! SKView!
skView.scene!.paused = true
return true
}
func bannerViewActionDidFinish(banner: ADBannerView!) {
print("Closed")
// If you want to continue game scene:
let skView: SKView = self.view as! SKView
skView.scene!.paused = false
}
你其余的朋友呢?是不是一旦点击了ADBannerView
,您就没有暂停游戏?查看bannerViewAction shouldBegin(\ubanner:ADBannerView!,willLeaveApplication willLeave:Bool)->Bool
@DanielStorm我添加了这些方法,但它们不会暂停游戏。我已经将我的方法更新到现在的状态。@Dashwuff谢谢你让我知道。既然iAd已经消失了,那么alternte又是什么呢?@Dashwuff事实上,似乎销售广告的苹果方面是唯一关闭的。不是iAd本身,@DanielStorm,嗯,好吧。这…让人困惑。消息来源确实表明网络成瘾正在消退,但可能没有我想象的那么快。(我最初的陈述是基于,这似乎不准确。)