美文网首页
iOS解决单击和双击手势冲突问题

iOS解决单击和双击手势冲突问题

作者: crazy一笑 | 来源:发表于2021-11-04 08:27 被阅读0次
            //单击手势
            let tap = UITapGestureRecognizer(target: self, action: #selector(tapAct))
            tap.numberOfTapsRequired = 1
            contentView.addGestureRecognizer(tap)
    
            //双击手势
            let tap2 = UITapGestureRecognizer(target: self, action: #selector(tap2Act))
            tap2.numberOfTapsRequired = 2
            contentView.addGestureRecognizer(tap2)
            
          //关键代码
         tap.require(toFail: tap2)
    
        @objc private func tapAct() {
            print("tap act....")
        }
        
        @objc private func tap2Act() {
            print("tap 2 act....")
        }
    

    相关文章

      网友评论

          本文标题:iOS解决单击和双击手势冲突问题

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