iphone - UILongPressGestureRecognizer gets called twice when pressing down -


i detecting if user has pressed down 2 seconds:

uilongpressgesturerecognizer *longpress = [[uilongpressgesturerecognizer alloc]                                              initwithtarget:self                                               action:@selector(handlelongpress:)];         longpress.minimumpressduration = 2.0;         [self addgesturerecognizer:longpress];         [longpress release]; 

this how handle long press:

-(void)handlelongpress:(uilongpressgesturerecognizer*)recognizer{     nslog(@"double oo"); } 

the text "double oo" gets printed twice when press down longer 2 seconds. why this? how can fix?

uilongpressgesturerecognizer continuous event recognizer. have @ state see if start, middle or end of event , act accordingly. i.e. can throw away events after start, or @ movement need. class reference:

long-press gestures continuous. gesture begins (uigesturerecognizerstatebegan) when number of allowable fingers (numberoftouchesrequired) have been pressed specified period (minimumpressduration) , touches not move beyond allowable range of movement (allowablemovement). gesture recognizer transitions change state whenever finger moves, , ends (uigesturerecognizerstateended) when of fingers lifted.

now can track state this

-  (void)handlelongpress:(uilongpressgesturerecognizer*)sender {      if (sender.state == uigesturerecognizerstateended) {       nslog(@"uigesturerecognizerstateended");     //do whatever want on end of gesture      }     else if (sender.state == uigesturerecognizerstatebegan){        nslog(@"uigesturerecognizerstatebegan.");    //do whatever want on began of gesture      }   } 

Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -