Aluminum
Aluminum

Reputation: 2992

How start an IBAction by dragging on a UIButton?

I need help with my iPhone application. I currently have 5 UIButtons in a view linked with different IBActions. The buttons are placed one close to each other. I would like to know how to make the user able to press all the buttons just by dragging his finger on the buttons instead of pulling the finger away from the screen of his device and tap on a different button.

If you can't understand how the buttons are placed here's a picture ^.^

enter image description here

Thanks!

Upvotes: 2

Views: 2195

Answers (2)

Old McStopher
Old McStopher

Reputation: 6349

In each of the buttons, you could set the Touch Drag Outside event AND the Touch Drag Enter button event from the Connections Inspector to call the appropriate IBAction, so that the method is called when any one of them is touched and while the finger is still dragging toward the others. It may require two events for every button, depending on what exact behaviour you're looking for.

Remember that although it may deviate from the Model-View-Controller (MVC) way of doing things, one can set an IB element to call multiple IBActions and multiple events can be used to call the same IBAction.

The events will be listed in the connection inspector after you select each button. Press CMD+2 to jump to the connection inspector tab.

Upvotes: 2

Merky
Merky

Reputation: 494

I suppose one option would be to use the TouchesXX event(s). For instance you could pick up on touches dragged and in code you could fire the button event handlers (the IBActions). Of course you would have to know the locations of the other buttons to determine if they have been dragged over. I'm not sure if that is what you are looking for but that would be one option.

Upvotes: 1

Related Questions