iOS UIView同时处理单击和双击手势 (Swift语言)

直接上代码

// 单击消失
    let singleTapGesture = UITapGestureRecognizer(target: self, action: #selector(handleSingleTap(gesture:)))
    singleTapGesture.numberOfTapsRequired = 1
    addGestureRecognizer(singleTapGesture)
    // 双击缩放
    let doubleTapGesture = UITapGestureRecognizer(target: self, action: #selector(handleDoubleTap))
    doubleTapGesture.numberOfTapsRequired = 2
    addGestureRecognizer(doubleTapGesture)
    //**关键**
    // 只有当没有检测到双击时才执行单击操作
    singleTapGesture.require(toFail: doubleTapGesture)

你可能感兴趣的:(iOS UIView同时处理单击和双击手势 (Swift语言))