Debashis
Debashis

Reputation: 1015

Dragging to fire UIButtons

I have four UIButtons on a UIView in an iPad application being developed at the moment for iPad Simulator 3.2.

What currently happens is this: The user drags their finger from one button to another. As the finger leaves the first button, that button remains in its active state, and nothing happens as the finger passes over the second button unless the user releases the touch and taps the screen again on the second button.

What I need to happen is, the moment their finger leaves the area of the first UIButton, it should go back to its default UI state, and when the finger enters the area of the second UIButton, the second button should assume its active state, and fire an event.

I'm really completely lost as to how to accomplish this, I've done lots of Googling, nothing has offered a quick solution to what seems to me like something that should be easy to accomplish.

Thanks in advance.

Upvotes: 3

Views: 466

Answers (2)

Alex Wayne
Alex Wayne

Reputation: 186984

You probably don't want to use UIButtons here. Instead create your own view, and do touch handling yourself. You can easily track the X and Y position of any view inside your custom view and respond accordingly.

UIButtons just are not designed for this kind of use.

Upvotes: 1

SomeRandomGuy
SomeRandomGuy

Reputation: 486

Look into modifying the actions for your button to use one of the many different control events available. Namely, this sounds like you need to register your buttons to perform actions on UIControlEventTouchDragEnter and/or UIControlEventTouchDragExit.

Upvotes: 1

Related Questions