ios - How to add touch event for custom uicontrol and controller? -


i have custom uicontrol has 3 subviews. each of subviews, add target:

button.addtarget(self, action: #selector(buttontapped(clickedbtn:)), for: .touchupinside) 

within function buttontapped, special animations transitions (it mimics segmented control).

now, within viewcontroller custom uicontrol exists in must know when it's touched. created @ibaction function interacts touch events custom uicontrol.

the problem is, isn't possible (as far know). if add target touch event subviews, parent touch events won't called. have parent view called @ibaction function, must set subview's setuserinteractiveenabledtotrue`. when that, subview's touch event functions won't called.

i need both touch event functions called. how can this? or what's best way around this?

use delegates, add protocol in uicontrol needs implemented in viewcontroller.

this way can detect if button clicked in uicontrol , invoke specific function in vc.

for example:

//youruicontrol.swift protocol youruicontroldelegate {   func didtapfirstbutton() }  class youruicontrol : uiview { //i'm assuming create uicontrol uiview    var delegate : youruicontroldelegate?   //other codes here   .   .   .   @ibaction func tapfirstbutton(_ sender: anyobject) {      if let d = self.delegate {        d.didtapfirstbutton()      }   } }  //yourviewcontroller.swift extension yourviewcontroller : uicontroldelegate {   func didtapfirstbutton() {      //handle first button tap here   } } 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -