title: Trigger an action when a CALayer is touched?
body: <p>So I have been looking all over and I haven't quite found what I am looking for.</p>
  
  <p>I have a view and then a subview of that view.  On that second view I create CALayers depending on what coordinates I give it.  I want to be able to touch any of those CALayers and trigger something.</p>
  
  <p>I have found different pieces of code that look like they can help, but I haven't been able to implement them.</p>
  
  <p>For example:</p>
  
  <pre><code>-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { if ([touches count] == 1) { for (UITouch *touch in touches) {
  
  CGPoint point = [touch locationInView:[touch view]]; point = [[touch view] convertPoint:point toView:nil];
  
  CALayer *layer = [(CALayer *)self.view.layer.presentationLayer hitTest:point];
  
  layer = layer.modelLayer; layer.opacity = 0.5;
  
  } } } 
  </code></pre>
  
  <p>and also this....</p>
  
  <pre><code>- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
  
      UITouch *touch = [touches anyObject];
  
      // If the touch was in the placardView, bounce it back to the center
      if ([touch view] == placardView) {
          // Disable user interaction so subsequent touches don't interfere with animation
          self.userInteractionEnabled = NO;
          [self animatePlacardViewToCenter];
          return;
      }       
  }
  </code></pre>
  
  <p>I am still pretty much a beginner to this stuff.  I was wondering if anyone can tell me how to do this.  Thanks for any help.</p>