In my code i add the gestures to an array. That what i mentioned:
- (void)handlePanGesture:(UIPanGestureRecognizer *)panGestureRecognizer{
[arrayLineGestures addObject:panGestureRecognizer];
[arrayAllGestures addObject:[arrayLineGestures copy]];
}
So after a time i wanna use them again and i use this code:
for (int i=0; i<[arrayAllGestures count]; i++) {
for (int k=0;k<[[arrayAllGestures objectAtIndex:i]count]; k++) {
UIPanGestureRecognizer *panGestureRecognizer=(UIPanGestureRecognizer *)[[arrayAllGestures objectAtIndex:i]objectAtIndex:k];
const CGPoint point = [[CCDirector sharedDirector] convertToGL:[panGestureRecognizer locationInView:panGestureRecognizer.view]];
if (panGestureRecognizer.state == UIGestureRecognizerStateBegan) {Nslog(@"began")}
But this code doesn’t work. It shows the pangesture state as UIGestureRecognizerStatePossible.But before i add them to the array i checked the states no one is UIGestureRecognizerStatePossible. I couldn’t see the mistake.
Thanks.
The
stateof anyUIGestureRecognizerwill only be valid for the time you are in your handler. ThepanGestureRecognizerthat you are passed in is not a snapshot of state, but rather an object reference to the recognizer. When you store it off in an array and try to reference it later, thestateisn’t valid because the life-cycle of the recognizer has likely expired.If you iterate through your array, you’ll probably find that all of the recognizers are the same object. I don’t know if this is guaranteed though, so don’t rely on that.