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
Post a Comment