Vignesh
Vignesh

Reputation: 10251

Touch detection with UIButton

I am facing a problem in using UIButton action and touchesmoved. The scenario is, when I drag my fingers over a series of buttons its actions should be called.I button can be touched individually as well.

I used the touchesmoved method to find out the touch points on uibutton to trigger its action. The problem with that approach is, When I tap somewhere in view and move my finger over button everything works, but if I start my touch on UIButton itself touchesmoved method is not called.

Upvotes: 0

Views: 5683

Answers (2)

EmilioPelaez
EmilioPelaez

Reputation: 19874

If you don't need to know the exact location of the touch, just when they swiped over it, you can add a target to it and use one of the many UIControlEvents, like UIControlEventTouchDragInside, etc.

Here's the full enum straight from UIControl.h

enum {
    UIControlEventTouchDown           = 1 <<  0,      // on all touch downs
    UIControlEventTouchDownRepeat     = 1 <<  1,      // on multiple touchdowns (tap count > 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,     // sliders, etc.

    UIControlEventEditingDidBegin     = 1 << 16,     // UITextField
    UIControlEventEditingChanged      = 1 << 17,
    UIControlEventEditingDidEnd       = 1 << 18,
    UIControlEventEditingDidEndOnExit = 1 << 19,     // 'return key' ending editing

    UIControlEventAllTouchEvents      = 0x00000FFF,  // for touch events
    UIControlEventAllEditingEvents    = 0x000F0000,  // for UITextField
    UIControlEventApplicationReserved = 0x0F000000,  // range available for application use
    UIControlEventSystemReserved      = 0xF0000000,  // range reserved for internal framework use
    UIControlEventAllEvents           = 0xFFFFFFFF
};
typedef NSUInteger UIControlEvents;

Upvotes: 0

Related Questions