title: Capturing touches on a subview outside the frame of its superview using hitTest:withEvent:
body: <p><strong>My problem:</strong> I have a superview <code>EditView</code> that takes up basically the entire application frame, and a subview <code>MenuView</code> which takes up only the bottom ~20%, and then <code>MenuView</code> contains its own subview <code>ButtonView</code> which actually resides outside of <code>MenuView</code>'s bounds (something like this: <code>ButtonView.frame.origin.y = -100</code>).</p>
  
  <p>(note: <code>EditView</code> has other subviews that are not part of <code>MenuView</code>'s view hierarchy, but may affect the answer.)</p>
  
  <p>You probably already know the issue: when <code>ButtonView</code> is within the bounds of <code>MenuView</code> (or, more specifically, when my touches are within <code>MenuView</code>'s bounds), <code>ButtonView</code> responds to touch events. When my touches are outside of <code>MenuView</code>'s bounds (but still within <code>ButtonView</code>'s bounds), no touch event is received by <code>ButtonView</code>.</p>
  
  <p><strong>Example:</strong></p>
  
  <ul>
  <li>(E) is <code>EditView</code>, the parent of all views</li>
  <li>(M) is <code>MenuView</code>, a subview of EditView</li>
  <li>(B) is <code>ButtonView</code>, a subview of MenuView</li>
  </ul>
  
  <p><strong>Diagram:</strong> </p>
  
  <pre><code>+------------------------------+
  |E                             |
  |                              |
  |                              |
  |                              |
  |                              |
  |+-----+                       |
  ||B    |                       |
  |+-----+                       |
  |+----------------------------+|
  ||M                           ||
  ||                            ||
  |+----------------------------+|
  +------------------------------+
  </code></pre>
  
  <p>Because (B) is outside (M)'s frame, a tap in the (B) region will never be sent to (M) - in fact, (M) never analyzes the touch in this case, and the touch is sent to the next object in the hierarchy.</p>
  
  <p><strong>Goal:</strong> I gather that overriding <code>hitTest:withEvent:</code> can solve this problem, but I don't understand exactly how. In my case, should <code>hitTest:withEvent:</code> be overridden in <code>EditView</code> (my 'master' superview)? Or should it be overridden in <code>MenuView</code>, the direct superview of the button that is not receiving touches? Or am I thinking about this incorrectly?</p>
  
  <p>If this requires a lengthy explanation, a good online resource would be helpful - except Apple's UIView docs, which have not made it clear to me.</p>
  
  <p>Thanks!</p>