UIScrollView在子视图中断开手势识别器

时间:2016-08-23 11:46:29

标签: swift autolayout snapkit

允许scrollview将手势传递给子视图的正确方法是什么?

1 个答案:

答案 0 :(得分:0)

您应该向ScrollView添加手势识别器,如下所示:

        let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: "handleTap:")
        scrollView.addGestureRecognizer(tapGestureRecognizer)

然后像这样处理水龙头:

func handleTap(tap: UITapGestureRecognizer)  {

        let location = tap.locationInView(tap.view)

        for i in 0..<scrollView.subviews.count{
            let subViewTapped = scrollView.subviews[i]
            if CGRectContainsPoint(subViewTapped.frame, location) {

        print("tapped subview at index\(i)")
                // do your stuff here

            }
        }

    }
相关问题