title: Custom UIButton drawing - stays depressed after touchesEnded
body: <p>I've made a custom zero-image, Core Graphics drawn UIButton based on <a href="http://www.raywenderlich.com/2134/core-graphics-101-glossy-buttons" rel="nofollow">Ray Wenderlich's Tutorial</a> (the only modifications are to CoolButton's <code>drawRect:</code> method, altered drawing code), and it works great most of the time. However, sometimes when I click it for a short period of time, it stays in a depressed state and doesn't return to normal. </p>
  
  <p>From here, the only way to get it back to a normal state is via a long press. Simply clicking means it stays depressed.</p>
  
  <p>Another thing to note is that I've hooked Touch Up Inside up to a chain of a few long methods - I don't think it would take more than 0.1 seconds to complete. I've even used <code>dispatch_async</code> in the <code>@selector</code> that is hooked up to Touch Up Inside, so there shouldn't be a delay in the UI updating, I think. </p>
  
  <hr>
  
  <p>I've put an <code>NSLog</code> in the <code>drawRect:</code> which fires 3 times per button press usually, and it varies what <code>UIControlState</code> the button is in for each press:</p>
  
  <ul>
  <li>For some short presses, it goes Highlighted, Highlighted, Normal</li>
  <li>for longer presses, it's Highlighted, Normal, Normal</li>
  </ul>
  
  <p>However, for very short presses, it only fires twice, Highlighted -> Highlighted.</p>
  
  <p>When it's a long press to get it back to Normal, it goes H, N, N.</p>
  
  <hr>
  
  <p>This has been puzzling me for a while, and I haven't been able to work out why short presses only fire <code>drawRect:</code> twice, or why <code>touchesEnded:</code> doesn't seem to call <code>drawRect:</code>. Perhaps <code>touchesEnded:</code> isn't firing?</p>
  
  <p>I really hope someone can help.</p>