ios - Swift: Remove ads different scene in Spritekit -
i'm using mopub banner ad, added following code view controller's viewdidload:
self.adview.delegate = self self.adview.frame = cgrectmake(0, self.view.bounds.size.height - mopub_banner_size.height, mopub_banner_size.width, mopub_banner_size.height) self.view.addsubview(self.adview) self.adview.loadad()
but makes ad visible in scenes when want visible in main menu scene.
how remove ad in scenes don't want be?
this might not best way this, simplest. use nsnotification
broadcast message viewcontroller
whenever wish show or hide banner.
for instance if add "observer" in viewcontroller
on init
or viewdidload
:
nsnotificationcenter.defaultcenter().addobserver( self, selector: "hidebannerad", name: "hidead", object: nil)
to make viewcontroller
listen message called "hidead"
, execute method called hidebannerad
.
then implement method:
func hidebannerad(){ self.adview.hidden = true }
be sure remove observer on deinit
, isn't issue persistance of viewcontroller
in spritekit
it's practice.
deinit{ nsnotificationcenter.defaultcenter().removeobserver(self) }
then, when want show or hide view, example on scene transition or game on method, can implement hidebannerad
method triggering observer using:
nsnotificationcenter.defaultcenter().postnotificationname("hidead", object: nil)
and banner should hide. can repeated similar showbannerad
method setting hidden
property false
, or can have single method toggles hidden property using adview.hidden = !adview.hidden
.
i hope helps.
Comments
Post a Comment