title: Cancel a UILongPressGestureRecognizer after a certain time
body: <p>I used a <code>UILongPressGestureRecognizer</code> in my <code>UICollectionView</code>. Now I when I hold my finger on the CollectionView items after a certain amount of time (for example 1 second), I want my <code>UILongPressGestureRecognizer</code> to end and execute a certain code:</p>
  
  <pre><code>if (gestureRecognizer.state == UIGestureRecognizerStateEnded) {}
  </code></pre>
  
  <p>This is my code:</p>
  
  <pre><code>- (void)viewDidLoad {
    [super viewDidLoad];
    Public = [[PublicMethods alloc]init];
    self.view.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.collect];
  
    UILongPressGestureRecognizer *lpgr = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(handleLongPress:)];
    lpgr.minimumPressDuration = 3; //seconds
    lpgr.delaysTouchesBegan = YES;
    lpgr.delegate = self;
    [self.collect addGestureRecognizer:lpgr];
  
  
  }
  -(void)handleLongPress:(UILongPressGestureRecognizer *)gestureRecognizer {
    if (gestureRecognizer.state != UIGestureRecognizerStateEnded) {
      return;
    }
  
    CGPoint p = [gestureRecognizer locationInView:self.collect];
    NSIndexPath *indexPath = [self.collect indexPathForItemAtPoint:p];
    if (indexPath == nil){
      NSLog(@"couldn't find index path");
    } else {
      // get the cell at indexPath (the one you long pressed)
      //CollectionViewCell* cell = (CollectionViewCell*)[self.collect cellForItemAtIndexPath:indexPath];
      UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"bala" message:@"jalaaaa" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:nil, nil];
      [alert show];
    }
  }
  </code></pre>