How to track button selection after long press?

I am trying to emulate a long keyboard press by suggesting a letter for a UIButton element . What I am trying to do is long press on the UIButton after you click on the 3 new buttons and select one of those 3 new buttons. just like suggesting keyboard letters.enter image description here

How can i do this? Any ideas? Thanks you

0


source to share


2 answers


You UIControl

only have UILongPressGestureRecognizer for this AND you can set the click time on the minimumPressDuration

property



If you need this behavior on UIButton

, you need to add this gesture recognizer to the button and handle the first call (single click).

+1


source


You have a full set of events in UIControl (UIButton is a subclass of it) to handle all the touch events you need:

enum {
   UIControlEventTouchDown           = 1 <<  0,
   UIControlEventTouchDownRepeat     = 1 <<  1,
   UIControlEventTouchDragInside     = 1 <<  2,
   UIControlEventTouchDragOutside    = 1 <<  3,
   UIControlEventTouchDragEnter      = 1 <<  4,
   UIControlEventTouchDragExit       = 1 <<  5,
   UIControlEventTouchUpInside       = 1 <<  6,
   UIControlEventTouchUpOutside      = 1 <<  7,
   UIControlEventTouchCancel         = 1 <<  8,

   UIControlEventValueChanged        = 1 << 12,

   UIControlEventEditingDidBegin     = 1 << 16,
   UIControlEventEditingChanged      = 1 << 17,
   UIControlEventEditingDidEnd       = 1 << 18,
   UIControlEventEditingDidEndOnExit = 1 << 19,

   UIControlEventAllTouchEvents      = 0x00000FFF,
   UIControlEventAllEditingEvents    = 0x000F0000,
   UIControlEventApplicationReserved = 0x0F000000,
   UIControlEventSystemReserved      = 0xF0000000,
   UIControlEventAllEvents           = 0xFFFFFFFF
};

      



  • UIControlEventTouchDown

    will fire when the button is pressed
  • UIControlEventTouchDownRepeat

    will fire if you keep holding the button (note that this event fires many times, so you should only handle the first one) - here you have to display the popover
  • UIControlEventTouchDragExit

    will light up when you take your finger out of the button - here you have to hide the popover
  • UIControlEventTouchDragEnter

    will fire when you drag your finger into the button - this is where you have to display the popover
  • UIControlEventTouchUpInside

    , UIControlEventTouchUpOutside

    and UIControlEventTouchCancel

    fires when you lift your finger from the button - here you have to hide the popover
  • and etc.

UPDATE
You will have some logic to implement to handle the movement of the finger inside the popover (because then you will be pulling out of the button).

+1


source







All Articles