swift - Closing iAD Banner causes the current scene to change -


i implemented iad, shows banner on bottom of screen. call function, showsad() in menu class , gamescene class show banner. gamescene gameplay happens. if click on iad banner in gamescene, automatically switches scene menu reason. online resources, code used show iad banner, in 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 takes animation complete     uiiad.alpha = 1 // fade in 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 takes animation complete     uiiad.frame = cgrectmake(0, sh - bv, 0, 0) // end position of animation     uiview.commitanimations()  }  func hidebannerad() {     uiiad.hidden = true     let bv = uiiad.bounds.height      uiview.beginanimations(nil, context: nil)     uiview.setanimationduration(0.01) // time takes animation complete     uiiad.frame = cgrectmake(0, sh + bv, 0, 0) // end position of animation     uiview.commitanimations() } 

then in gamescene , menu class, use show iad banner:

func showads(){     nsnotificationcenter.defaultcenter().postnotificationname("showadsid", object: nil) } 

i tried pausing, didn't work. here's code:

func bannerviewactionshouldbegin(banner: adbannerview!, willleaveapplication willleave: bool) -> bool {         print("clicked")          iadbanner.delegate = self         // if want pause game scene:         let skview: skview = self.view as! skview!         skview.scene!.paused = true          return true     }     func bannerviewactiondidfinish(banner: adbannerview!) {         print("closed")          // if want continue game scene:         let skview: skview = self.view as! skview         skview.scene!.paused = false     } 


Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

Cross-Compiling Linux Kernel for Raspberry Pi - ${CCPREFIX}gcc -v does not work -

java.lang.NoClassDefFoundError When Creating New Android Project -