ios - how to prevent a UITapGestureRecognizer in a background view from being called when clicking on an overlay -
i have background dimmedview uitapgesturerecognizer. however, when click on overlayview, background uitapgesturerecognizer called. intended behavior? putting userinteractionenabled=false on our overlay still has background uitapgesturerecognizer called. how make overlay prevents uitapgesturerecognizer on background view (self.dimmedview) being called.
here's code:
func renderoverlaynav(){ println("yyy render outlay") self.dimmedview=uiview(frame: cgrectmake(0.0, 0.0, self.screenwidth, self.screenheight)) self.dimmedview.backgroundcolor=uicolor.blackcolor().colorwithalphacomponent(0.5) let dimmedviewtap = uitapgesturerecognizer(target: self, action:selector("tapondimmedview:")) self.dimmedview.addgesturerecognizer(dimmedviewtap) self.modalview=uiview(frame: cgrectmake(50.0, 144.0, (self.screenwidth-100), (self.screenheight - 200))) self.modalview.backgroundcolor=uicolor.whitecolor() self.modalview.userinteractionenabled=false let modalscrollview = uiscrollview(frame: cgrectmake(10.0, 10.0, 200.0, 200.0)) modalscrollview.scrollenabled=true modalscrollview.userinteractionenabled=false let closemodalbtn = uibutton(frame: cgrectmake(10.0, 10.0, 40.0, 40.0)) closemodalbtn.titlelabel!.text="x" closemodalbtn.backgroundcolor = uicolor.bluecolor() self.modalview.addsubview(closemodalbtn) let closemodalbtntap = uitapgesturerecognizer(target: self, action:selector("tapclosemodalbtn:")) closemodalbtn.addgesturerecognizer(closemodalbtntap) } func tapondimmedview(recognizer: uitapgesturerecognizer) { println("you tapped on \(recognizer.view) @ \(nsdate().timeintervalsince1970)") }
basically, clicking dimmed view or white part causes tapondimmedview called.
make view white color view.userinteractionenabled = true
Comments
Post a Comment