【问题标题】:Long Press Gesture called multiple times长按手势多次调用
【发布时间】:2019-01-16 15:45:35
【问题描述】:

我遇到了 UILongPressGestureRecognizer 的问题,我使用了以下代码:-

func addLongPressGesture(){
        let lngPr = UILongPressGestureRecognizer.init(target: self, action: #selector(self.handleLongPress(gesture:)))
        lngPr.delaysTouchesEnded = true
        self.addGestureRecognizer(lngPr)
    }
    @objc func handleLongPress(gesture:UIGestureRecognizer){
       
        if selectedIndexPath != nil && delegate != nil{
            self.delegate?.delegateLongPressed(atIndexPath: selectedIndexPath!)
        }
    }

【问题讨论】:

    标签: ios swift long-press swift4.1 uilongpressgesturerecogni


    【解决方案1】:

    你需要检查 UILongPressGesture 的状态来修改你的函数 试试这个:-

    func addLongPressGesture(){
            let lngPr = UILongPressGestureRecognizer.init(target: self, action: #selector(self.handleLongPress(gesture:)))
            lngPr.delaysTouchesEnded = true
            self.addGestureRecognizer(lngPr)
        }
        @objc func handleLongPress(gesture:UIGestureRecognizer){
            if gesture.state == .ended{
            if selectedIndexPath != nil && delegate != nil{
                self.delegate?.delegateLongPressed(atIndexPath: selectedIndexPath!)
            }
            }
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多