【问题标题】:Stop UILongPressGestureRecognizer when finger leaves view当手指离开视图时停止 UILongPressGestureRecognizer
【发布时间】:2019-08-17 08:08:19
【问题描述】:

当触发UILongPressGestureRecognizer 的触摸离开手势也被绑定的视图时,我如何停止甚至检测?这种行为可以在UIButtons 上看到,当手指离开按钮时,触摸事件将停止。

【问题讨论】:

    标签: ios cocoa-touch uiview uigesturerecognizer


    【解决方案1】:

    您可以使用简单的 sn-p 检测离开和进入,如下所示:

     @objc   func handleLongPress(_ recognizer:UILongPressGestureRecognizer) {
    
    
    switch recognizer.state {
     case .changed:
        if let view = recognizer.view {
            if view.bounds.contains(recognizer.location(in: recognizer.view) ) {
                  print("inside view")
            }
            else {
                print("out of view")
            }
        }
      default:
        break;
      }
      }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-18
      • 1970-01-01
      • 1970-01-01
      • 2015-12-14
      • 2019-04-30
      相关资源
      最近更新 更多