问题
I have several buttons in my view built using IB. Each button triggers a short audio sound.
I want to be able to drag my finger over them to trigger them... just like you are dragging your finger over piano keys (don't worry I am not making a piano app)
I cant figure out how to recognize a touch outside the button and then inside it.
Any ideas?
Thanks
回答1:
As your buttons subclass from UIControl, you can use UIControl's implementation of recognition of gestures.
Look at UIControl's - (void)addTarget:(id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents
. This will let you specify a method on an object to be called whenever certain events occur. The possible events are, among others:
UIControlEventTouchDragInside = 1 << 2,
UIControlEventTouchDragOutside = 1 << 3,
UIControlEventTouchDragEnter = 1 << 4,
A complete list is available in Apple's documentation for Control Events.
When UIControlEventDragOutside
fires, you may want to reevaluate which view is currently playing.
来源:https://stackoverflow.com/questions/1345154/how-do-you-recognize-drag-gestures