title: UIControl derived class & need to call drawRect twice to draw correct control state
body: <p>I have a class that inherits from UIControl that handles touchEvents and I don't understand why the 'setNeedsDisplay' method needs to invoked twice on touchEvents in order to have the correct state drawn in the UI. I've seen this pattern in a few examples where the various touches[Began|Ended] methods all invoke setNeedsDisplay directly and then once again with a delay using performSelector. </p>
  
  <p>I can see what the result is when the 2nd setNeedsDisplay isn't invoked - the control is first rendered in the selected state but doesn't revert to normal state so the background remains as selected.</p>
  
  <p>Why exactly does this behavior happen? </p>
  
  <pre><code>// a class that inherits from UIControl
  - (void)drawRect:(CGRect)rect
  {
      NSLog(@"drawRect, control state: %d", self.state);
      if (self.state == UIControlStateNormal)
      {
          [self setContentToNormalState];
          [self setBackgroundColor:[UIColor whiteColor]];
          NSLog(@"Set background color: White");
      }
      else 
      {
          [self setContentToSelectedState];
          [self setBackgroundColor:[UIColor lightGrayColor]];
          NSLog(@"Set background color: Grey");
      }
  
      [super drawRect:rect];
  }
  
  - (void)hesitateUpdate
  {
      [self setNeedsDisplay];
  }
  
  #pragma mark - Touch event handling
  
  - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
      [self setHighlighted:YES];
      [self setNeedsDisplay];
      [super touchesBegan:touches withEvent:event];
  }
  
  - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
  {
      [self setHighlighted:NO];    
      [super touchesMoved:touches withEvent:event];
  //    [self setNeedsDisplay];    
  }
  
  - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
      [super touchesCancelled:touches withEvent:event];
      [self setHighlighted:NO];
  
      [self setNeedsDisplay];
      [self performSelector:@selector(hesitateUpdate) withObject:nil afterDelay:0.1];
  }
  
  - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
  {
      [super touchesEnded:touches withEvent:event];
      [self setHighlighted:NO];
  
      [self setNeedsDisplay];
      // Even with the following, if I tap and hold momentarily in the simulator, 
      // sometimes, the control has the gray background instead of white at the end
      [self performSelector:@selector(hesitateUpdate) withObject:nil afterDelay:0.1];     
  }
  </code></pre>