Jonathan
Jonathan

Reputation: 631

How do you recognize drag gestures

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

Upvotes: 1

Views: 2830

Answers (1)

NSSec
NSSec

Reputation: 4551

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.

Upvotes: 4

Related Questions