美文网首页
iOS UIView同时处理单击和双击手势 (Swift语言)

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

作者: 与之书 | 来源:发表于2017-11-27 16:57 被阅读16次

    直接上代码

    // 单击消失
        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语言)

          本文链接:https://www.haomeiwen.com/subject/ncpdbxtx.html