Swift3 添加约束后,点击手势不起作用

Swift3 添加约束后,点击手势不起作用,swift3,uiscrollview,uitapgesturerecognizer,Swift3,Uiscrollview,Uitapgesturerecognizer,在添加约束之前,我的代码工作得非常好。一旦添加了约束,点击手势似乎就不起作用了。 我的代码如下: //this is in viewDidLoad() containerView.translatesAutoresizingMaskIntoConstraints = false scrollView.addSubview(containerView) self.view.addSubview(scrollView) if

在添加约束之前,我的代码工作得非常好。一旦添加了约束,点击手势似乎就不起作用了。 我的代码如下:

    //this is in viewDidLoad()
        containerView.translatesAutoresizingMaskIntoConstraints = false

        scrollView.addSubview(containerView)
        self.view.addSubview(scrollView)

        if #available(iOS 11.0, *) {

            let top = NSLayoutConstraint.init(item: containerView, attribute: .top, relatedBy: .equal, toItem: self.view.safeAreaLayoutGuide, attribute: .top, multiplier: 1.0, constant: 0.0)
            let leading = NSLayoutConstraint.init(item: containerView, attribute: .leading, relatedBy: .equal, toItem: self.view, attribute: .leading, multiplier: 1.0, constant: 0.0)
            let trailing = NSLayoutConstraint.init(item: containerView, attribute: .trailing, relatedBy: .equal, toItem: self.view, attribute: .trailing, multiplier: 1.0, constant: 0.0)
            let height = NSLayoutConstraint.init(item: containerView, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1.0, constant: 60.0)

            NSLayoutConstraint.activate([top, leading, trailing, height])

        } else {
            // Fallback on earlier versions
        }

        self.automaticallyAdjustsScrollViewInsets = false

    //This is inside a function where I create subviews
        containerView.addSubview(DiaryList)

        let tapGesture = AddMyTapGesture(target: self, action: #selector(handleTap))
        tapGesture.title = date
        tapGesture.titleFormat = dateFormat
        DiaryList.addGestureRecognizer(tapGesture)
        DiaryList.isUserInteractionEnabled = true

  //this is the tap gesture 
      @objc func handleTap(sender: AddMyTapGesture) {
              print("tapped")
          }

有什么解决办法吗?我也有同样的问题,在寻找答案