title: Pragmatic way of handling mouse in Core Animation layers
body: <p>I'm starting working with <strong>Core Animation</strong> and I started wondering how to handle various kinds of mouse events like</p>
  
  <ol>
  <li>mouse entered a <code>CALayer</code></li>
  <li>mouse exited a <code>CALayer</code></li>
  <li>mouse click on a <code>CALayer</code></li>
  </ol>
  
  <p>For now I'm concentrating just on <code>mouseDown</code> message sent to my custom view. According to the documentation I should use <code>-hitTest:(CGPoint)point</code> calling on my root layer (the one set with <code>[customView setLayer:rootLayer]</code>).</p>
  
  <p>It should return the farthest layer in the tree that is in position specified by point. So I did:</p>
  
  <pre><code>[rootLayer hitTest:[event locationInWindow]]
  </code></pre>
  
  <p>but it doens't work. It seems to work if I just click on <code>rootLayer</code>, otherwise it returns just <code>null</code>. Of course sublayers are added to rootLayer (infact they are drawn)</p>
  
  <p>Am I missing some kind of coordinate conversion? Apart from that, is it the way to handle mouse clicks?</p>
  
  <p>To find whenever mouse enters a CALayer do I have to keep hit testing for every movement update of the mouse?</p>
  
  <p>Thanks in advance</p>