UIButton events. What's the difference?

Solution 1:

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.

Solution 2:

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?