0
votes

Is there any way to animate buttons and call action metods like in iOS 7 standard calculator? I mean, a button highlights when a user holds finger on it and calls action method if user touches up.

I use Touch Up Inside event, but it works only with single button. When you touch down one button it highlights while you touch up finger. And then calls action method of first pressed button, doesn't matter where you cancelled touch.

I want to call action method of button, which you touches up. And highlight any button, that you are hold at the moment (not only button, that first touched).

What touch event can I use to do it?

P.S. Sorry for bad english.

1

1 Answers

4
votes

It would be really helpful if you included some more details before asking the question. For instance, are you creating the buttons programmatically or are you using the storyboard?

Either way you have to hook up methods to some of the other UIControlEvents as well as UIControlEventTouchDownand UIControlEventTouchUpInside.

if you cancel a button on UIControlEventTouchDragExitand let UIControlEventTouchDragEnter highlight the button in addition you should be well on your way to achieving your goal I would think. Example:

    [button addTarget:self
           action:@selector(highlightButton:)
 forControlEvents:UIControlEventTouchDown | UIControlEventTouchDragEnter];

As you confirm below that you're using storyboard, the following sent events are probably the ones you should hook up to your code:

Touch Down -> highlight
Touch Drag Enter -> highlight
Touch Drag Exit -> cancel
Touch Up Inside -> fire

Hopefully this should be enough to get you going.