简体   繁体   English

每次点击屏幕都会调用NSNotification

[英]NSNotification is called every time I tap the screen

I my game I am sending out an NSNotification to hide the banner ad during the game and show the banner ad on the main menu and game over scenes. 在我的游戏中,我正在发送NSNotification来隐藏游戏期间的横幅广告,并在主菜单和游戏场景上方显示横幅广告。 This works fine except for some reason every time I tap on the screen the notification to hide the ad is called and the ad disappears. 这项工作正常,但由于某种原因,每次我在屏幕上点击时,都会调用隐藏广告的通知,并且广告消失。 Here is the code to setting up the notifications in the GameViewController: 以下是在GameViewController中设置通知的代码:

NSNotificationCenter.defaultCenter().addObserver(self, selector: "showBanner:", name: "showAdBanner", object: nil)

NSNotificationCenter.defaultCenter().addObserver(self, selector: "hideBanner:", name: "hideAdBanner", object: nil)

And then the two functions: 然后是两个功能:

func showBanner(notification: NSNotification){

        self.googleBannerView.hidden = false
        var request: GADRequest = GADRequest()
        self.googleBannerView.loadRequest(request)
        println("show banner")

}

func hideBanner(notification: NSNotification){

        self.googleBannerView.hidden = true
        println("hide banner")

}

In the main menu scene and game over scene: 在主菜单场景和游戏结束场景中:

NSNotificationCenter.defaultCenter().postNotificationName("showAdBanner", object: nil)

Then in the game scene: 然后在游戏场景中:

NSNotificationCenter.defaultCenter().postNotificationName("hideAdBanner", object:nil)

It is very strange why when ever I tap the screen on the main menu scene and game over screen the ad banner disappear. 奇怪的是,为什么我每次在主菜单场景上点击屏幕并在屏幕上方进行游戏时广告横幅就会消失。 Any ideas? 有任何想法吗? I really need help this is the only thing holding me back from publishing my game. 我真的需要帮助,这是阻止我发布游戏的唯一原因。 Thank you in advance. 先感谢您。

-Vinny -温妮

When you display your banner you would need to reduce your games scene by the frame of the banner. 当显示横幅时,您需要按照横幅的框架缩小游戏场景。

In iOS, SCNView is a subclass of UIView 在iOS中,SCNView是UIView的子类

so just resize your SCNView so that both of the fit on the screen at the same time... 因此,只需调整SCNView的大小,以使两者同时适合屏幕显示...

Okay, I fixed it. 好的,我修复了它。 All I did was change the location where I post the notification. 我所做的就是更改发布通知的位置。 I changed it to hide when I press the play and try again buttons. 按下播放按钮并重试按钮时,将其更改为隐藏。 Thank you so much for everyone's help! 非常感谢大家的帮助! -Vinny -温妮

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM