title: Handling UITapGestureRecognizer in custom view
body: <p>I have a custom view class. Inside my view controller I add a Tap gesture recognizer on this view object. Now, in the handler of tap gesture I am setting up a property on my view object which I am trying to fetch in the drawRect of my view class. Now, surprisingly when I print view objects in my "handleGesture" &amp; "drawRect", I get two different objects. Because of this my if condition inside drawRect do not get execute. What could be the reason?</p>
  
  <p>It do not come in state UIGestureRecognizerStateBegan. It always coming inside UIGestureRecognizerStateEnded.</p>
  
  <pre><code>// Adding Gesture in my view
   MyCustomView *customView= [[[MyCustomView alloc] init] autorelease];
  UIGestureRecognizer *GestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleGesture:)];
          [customView addGestureRecognizer:GestureRecognizer];
          [GestureRecognizer release];
  
  // Handling tap on my view
  - (void)handleGesture:(UIGestureRecognizer *)GestureRecognizer; {
      MyCustomView *aView= (MyCustomView *)GestureRecognizer.view;
  switch (iGestureRecognizer.state) {
      case UIGestureRecognizerStateBegan:
          NSLog(@"Began");
          [aView setNeedsDisplay];
          aView.touchDown = YES;
          break;
      case UIGestureRecognizerStateEnded:    
          NSLog(@"Ended");
          aView.touchDown = NO;
          [aView setNeedsDisplay];
          break;
      default:
          break;
  }
  }
  
  // Inside my view class
  - (void)drawRect:(CGRect)iRect {
      if (self.touchDown) {
  // Do something here
  }
  }
  </code></pre>