objective c - iOS fetch UIButton current UIControlEventType at @selector -


let abutton = uibutton() a.addtarget(self, action: "handler:", forcontrolevents: .touchupinside)  func handler(btn: uibutton) {     //is there anyway can know controlevent "touchupinside" in method? } 

as example above, wanna know controleventtype @ @selector, not found correct api or it's impossible?

you can either provide different methods different control events:

a.addtarget(self, action: "touchdownhandler:", forcontrolevents: .touchdown) a.addtarget(self, action: "touchuphandler:", forcontrolevents: .touchupinside)  func touchdownhandler(btn: uibutton) { }  func touchuphandler(btn: uibutton) { } 

as noted in another answer can event in handler , inspect type of touch, here in swift:

a.addtarget(self, action: "handletouch:event:", forcontrolevents: .alltouchevents)  // ...  func handletouch(button: uibutton, event: uievent) {     if let touch = event.touchesforview(button)?.first as? uitouch {         switch touch.phase {         case .began:             println("touch began")          case .ended:             println("touch ended")          case .moved:             println("touch moved")          case .cancelled:             println("touch cancelled")          case .stationary:             println("touch stationary")          }     } } 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -