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

时间:2017-12-04 05:23:48

标签: swift3 uiscrollview uitapgesturerecognizer

我的代码完全正常,直到添加了约束。一旦添加了约束,点击手势似乎不起作用。 我的代码如下:

    //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")
          }

0 个答案:

没有答案