title: Capturing and recording touch events on UIView
body: <p>I'm trying to subclass UIView and design a transparent view. This view will sit on top of many other views and it's only task is to capture and record user touches (tap and pan). I have tried many different methods, explained in different questions asked by other users with no luck. This is what I have done so far in my implementation file:</p>
  
  <pre><code>#import "touchLayer.h"
  
  @implementation touchLayer
  
  - (id)initWithFrame:(CGRect)frame
  {
      self = [super initWithFrame:frame];
      if (self) [self commonInit];
      return self;
  }
  
  - (id)initWithCoder:(NSCoder *)aDecoder
  {
      self = [super initWithCoder:aDecoder];
      if (self) [self commonInit];
      return self;
  }
  
  - (void)commonInit
  {
      self.userInteractionEnabled = YES;
      self.alpha = 0.0;
  }
  
  - (id)hitTest:(CGPoint)point withEvent:(UIEvent *)event
  {
      id hitView = [super hitTest:point withEvent:event];
      if (hitView == self)
      {
          UITouch *touch = [[event allTouches] anyObject];
  
          if (touch.phase == UITouchPhaseBegan) NSLog(@"touchesBegan");
          else if (touch.phase == UITouchPhaseMoved) NSLog(@"touchesMoved");
          else if (touch.phase == UITouchPhaseEnded) NSLog(@"touchesEnded");
  
          return nil;
      }
      else
          return hitView;
  }
  
  @end
  </code></pre>
  
  <p>Now this code works just fine, and I see see the touches in the lower layers, but I cannot differentiate between touchBegan, touchMoved, and touchEnded. <code>[[event allTouches] anyObject]</code> returns <strong><em>nil</em></strong>. Do you have any idea how I can capture tap and pan on a UIView without blocking the touches? Thanks a lot.</p>