如何为uiview的不同部分添加多个UITapGestureRecognizer?

时间:2015-09-05 04:13:29

标签: ios swift uitapgesturerecognizer

说,我有一个宽度为100的UIView

是否可以添加2个这样的手势识别器:

rightTapGesture为视图的右侧50和 leftTapGesture用于其他50个视图?

我不能使用标签式按钮!

1 个答案:

答案 0 :(得分:4)

UIGestureRecognizerDelegate

func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldReceiveTouch touch: UITouch) -> Bool {
    switch gestureRecognizer {
    case leftTapGesture:
        return touch.locationInView(theView).x < 50
    case rightTapGesture:
        return touch.locationInView(theView).x >= 50
    default:
        // cannot be here
        return false
    }
}