title: Tap Gesture Recognizer not received in custom UIView embedded in super view
body: <p>I am trying to create a custom UIView/Scrollview named <code>MyScrollView</code> that contains a few labels (UILabel), and these labels receive tap gestures/events in order to respond to user's selections <a href="https://i.stack.imgur.com/ChTfu.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ChTfu.png" alt="See the below screen shot for the custom UIView"></a>. </p>
  
  <p>In order to make the tap event work on the UILabels, I make sure they all have <code>userIteractionEnabled = true</code> and I created a delegate as below:</p>
  
  <pre><code>protocol MyScrollViewDelegate {
      func labelClicked(recognizer: UITapGestureRecognizer)
  }
  </code></pre>
  
  <p>The custom UIView is being used in <code>ScrollViewController</code> that I created, this <code>ScrollViewController</code> implements the delegate method as well:</p>
  
  <pre><code>import UIKit
  import Neon
  class ScrollViewController: UIViewController, MyScrollViewDelegate {
  
  var curQuestion: IPQuestion?
  var type: QuestionViewType?
  var lastClickedLabelTag: Int = 0 //
  
  init(type: QuestionViewType, question: IPQuestion) {
      super.init(nibName: nil, bundle: nil)
      self.curQuestion = question
      self.type = type
  }
  
  required init?(coder aDecoder: NSCoder) {
      fatalError("init(coder:) has not been implemented")
  }
  
  override func viewDidLoad() {
      super.viewDidLoad()
      self.automaticallyAdjustsScrollViewInsets = false
  }
  
  override func didReceiveMemoryWarning() {
      super.didReceiveMemoryWarning()
  }
  
  override func loadView() {
      view = MyScrollView(delegate: self, q: curQuestion!)
      view.userInteractionEnabled = true
  }
  }
  
  // implementations for MyScrollViewDelegate
  extension ScrollViewController {
  
  func labelTitleArray() -&gt; [String]? {
      print("labelTitleArray called in implemented delegate")
  
      return ["Comments", "Answers"]
  }
  
  func labelClicked(recognizer: UITapGestureRecognizer) {
      print("labelClicked called in implemented delegate")
      let controller = parentViewController as? ParentViewController
      controller?.labelClicked(recognizer)
      lastClickedLabelTag = recognizer.view!.tag
      }
  }
  
  // MARK: - handle parent's ViewController event
  extension QuestionDetailViewController {
      func updateActiveLabelsColor(index: Int) {
          print("updating active labels color: \(index)")
          if let view = view as? MyScrollView {
              for label in (view.titleScroll.subviews[0].subviews as? [UILabel])! {
                  if label.tag == index {
                      label.transform = CGAffineTransformMakeScale(1.1,1.1)
                      label.textColor = UIColor.purpleColor()
                  }
                  else {
                      label.transform = CGAffineTransformMakeScale(1,1)
                      label.textColor = UIColor.blackColor()
                  }
              }
          }
      }
  }
  </code></pre>
  
  <p>This above <code>ScrollViewController</code> is added, as a child view controller to the parent view controller, and positioned to the top part of the parent's view:</p>
  
  <pre><code>override func viewDidLoad() {
          super.viewDidLoad()
          self.automaticallyAdjustsScrollViewInsets = false
          self.view.backgroundColor = UIColor.whiteColor()
          addChildViewController(scrollViewController) // added as a child view controller here
          view.addSubview(scrollViewController.view) // here .view is MyScrollView
          scrollViewController.view.userInteractionEnabled = true
          scrollViewController.view.anchorToEdge(.Top, padding: 0, width: view.frame.size.width, height: 100)
      }
  </code></pre>
  
  <p>The app can load everything up in the view, but the tap gesture/events are not passed down to the labels in the custom <code>MyScrollView</code>. For this, I did some google search and have read <a href="https://developer.apple.com/library/ios/documentation/EventHandling/Conceptual/EventHandlingiPhoneOS/event_delivery_responder_chain/event_delivery_responder_chain.html" rel="nofollow noreferrer">Event Delivery: Responder Chain</a> on Apple Developer website and did a hit test as well. The <code>hitTest</code> function below can be triggered in the <code>MyScrollView</code>:</p>
  
  <pre><code>override func hitTest(point: CGPoint, withEvent event: UIEvent?) -&gt; UIView? {
          print("hit test started, point: \(point), event: \(event)")
          return self
      }
  </code></pre>
  
  <p>My observations with the <code>hitTest</code> is that the <code>touchesBegan()</code> and <code>touchesEnded()</code> methods are triggered in the view <em>only</em> when the <code>hitTest</code> function is there. Without <code>hitTest</code>, both functions do not get called with taps.</p>
  
  <p>but no luck getting the <code>UILabel</code> to respond to Tap Gestures. So I am reaching out to experts on SO here. Thanks for helping!</p>