71
votes

I've encountered a problem where my button should remain "pressed down" while it shows popover called from it. Popover is selector for some filter and filter is shown on button itself. When I tap on it and it shows popover it becomes deselected no matter what.

I think I have to redefine it's behavior on touch event and make it respond not to standart touch up inside. Then I wondered what are other events responsible for? But I couldn't find events list in iOS library and in StackOverflow are only questions about incorrect behavior of touch up inside or touch down.

So what's the difference betweeen touch events?

  1. touch cancel - when you touch button but move your finger away and it remains deselected?
  2. touch down - right on tap.
  3. touch down repeat ??
  4. touch drag enter ??
  5. touch drag exit ??
  6. touch drag inside ??
  7. touch drag outside ??
  8. touch up inside - when you tap and release button remaining in it's bounds . It changes UIButtons state to Normal.
  9. touch up outside - when you tap and release button leaving it's bounds ?

other IBActions are not sent by UIButton, right? Also how those events change UIButton's appearance? Like highlighted or selected?

I'd appreciate a link on good article about IBActions, because I couldn't find it.

2
@janusfidel thank you very much, it answered my question completely :)Protheus

2 Answers

148
votes

From Apple's doc for UIControlEvents:

  1. UIControlEventTouchCancel

    A system event canceling the current touches for the control.

  2. UIControlEventTouchDown

    A touch-down event in the control.

  3. UIControlEventTouchDownRepeat

    A repeated touch-down event in the control; for this event the value of the UITouch tapCount method is greater than one.

  4. UIControlEventTouchDragEnter

    An event where a finger is dragged into the bounds of the control.

  5. UIControlEventTouchDragExit

    An event where a finger is dragged from within a control to outside its bounds.

  6. UIControlEventTouchDragInside

    An event where a finger is dragged inside the bounds of the control.

  7. UIControlEventTouchDragOutside

    An event where a finger is dragged just outside the bounds of the control.

  8. UIControlEventTouchUpInside

    A touch-up event in the control where the finger is inside the bounds of the control.

  9. UIControlEventTouchUpOutside

    A touch-up event in the control where the finger is outside the bounds of the control.

11
votes

Listed in, what I would consider, order of common use/likelihood of occurrence for a normal button:

UIControlEventTouchDown: The user tapped the button. This fires on the finger/stylus making contact.

UIControlEventTouchUpInside: The user tapped the button. This fires on the finger/stylus contact pulled back away from the screen.


Useful for sliders and drag events like moving a component around. The below are in order of occurrence:

UIControlEventTouchDragInside: Triggered as the finger drags into the button area.

UIControlEventTouchDragExit: Triggered during a drag motion. It is called only once, as the users finger/stylus leaves the bounds of the button.

UIControlEventTouchDragOutside: Triggered during a drag motion, after 'UIControlEventTouchDragExit', and is called continuously, as long as the original touch continues.

UIControlEventTouchUpOutside: This is simply the finger/stylus being lifted BUT only if the finger/stylus is no longer within the bounds of the button. The important thing (and probably obviously) to call out is that the touch had to have been within the button at some point to associate this event with the button.

Note: My understanding is that the above can be helpful for:

  1. Sliders: as you might expect the touch may have been intentional but because of the quick swipe action, their finger movement may be sloppy and lift up outside of the slider area.
  2. Moving components around, as when you push things around a screen you want the movement to happen when the finger/stylus touches the border of the component/object.

Other events:

UIControlEventTouchCancel: Something out of the user's control is cancelling their touch action. Think of this as something "going wrong" on the phone side of things.

UIControlEventTouchDownRepeat: Want to detect when your user is mad and tapping a button furiously? Want to detect if they're still in Windows mode and are trying to "double click"? Or maybe you designed a button to do something different if they tap twice. This event helps with all of those!


References:

SO 1: Dif between UIControlEventTouchDragOutside and UIControlEventTouchDragExit

SO 2: What is UIControlEventTouchCancel?