views:

707

answers:

1

Hi,

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

+3  A: 

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.

MathieuK
Thanks for your reply.I checked out Apples Control Event Doc.UIControlEventTouchDragEnter sounds like exactly what I want."UIControlEventTouchDragEnterAn event where a finger is dragged into the bounds of the control."But it doesnt seem to work that way. It should say An event where a finger is Re-dragged into the bounds of the control.I cant get it to drag from outside to in?Anyways I will keep going at it.Cheers
Jonathan
You can use the events as a signal that something happened to the 'current view'. Then, not entirely sure it works this way, you could examine the current UITouch (specifically the view property) to determine where the finger is now.
MathieuK