title: How to limit a process between LongPressGesture-began and LongPressGesture-ended
body: <p>The requirement is simple: I want to start an activity (e.g. drawing circles on the screen) when the user touches the screen and holds down the finger. This activity shall stop immediately when the finger is lifted again. So I used the <code>UILongPressGestureRecognizer</code>. This produces a .began and .ended event. But the problem is that when an activity is launched based on the .began event, the .ended event will not happen as long as the activity is ongoing. My intention for the .ended event is that it shall stop the launched activity. In this way the activity  execution would be limited to the time between finger touch down and lift.</p>
  <p>I enhanced my sample code to even 2 independent <code>UILongPressGestureRecognizers</code> which can work simultaneously using the <code>UIGestureRecognizerDelegate</code> construct. The simultaneous function of the two recognizers works. However, when one of them launches the activity also the second recognizer does not receive events until the activity has ended.</p>
  <p>How can this trivial request be realized?</p>
  <p>Here is my sample code. The activity is simplified to 10 print statements. 1 per second. When the touch finger is lifted after 2 seconds, the loop will continue for the remaining 8 seconds.</p>
  <pre><code>import UIKit
  
  class ViewController: UIViewController {
      var fingerDown = false
  
      @IBOutlet var MyLongPress1: UILongPressGestureRecognizer!
  
      @IBOutlet var MyLongPress2: UILongPressGestureRecognizer!
  
      override func viewDidLoad() {
          super.viewDidLoad()
      }
  
      @IBAction func handleLongPress1(_ gesture: UILongPressGestureRecognizer) {
      
          if (gesture as AnyObject).state == .began {
              print(&quot;longPress1 began&quot;)
              fingerDown = true
              myActivity()
          } else  if (gesture as AnyObject).state == .ended {
              print(&quot;longPress1 ended&quot;)
              fingerDown = false
          }
      }
  
      @IBAction func handleLongPress2(_ gesture: UILongPressGestureRecognizer) {
      
          if (gesture as AnyObject).state == .began {
              print(&quot;longPress2 began&quot;)
              fingerDown = true
          } else  if (gesture as AnyObject).state == .ended {
              print(&quot;longPress2 ended&quot;)
              fingerDown = false
          }
      }
  
      func myActivity() {
          var count = 0
          while fingerDown &amp;&amp; count &lt; 10 {
              sleep(1)
              count += 1
              print(&quot;in myActivity \(count)&quot;)
          }
      }
  }
  
  extension ViewController: UIGestureRecognizerDelegate {
  
      func gestureRecognizer(
      _ gestureRecognizer: UIGestureRecognizer,
      shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer
      ) -&gt; Bool {
          return true
      }
  }
  </code></pre>
  <p>Any good advice would be appreciated!</p>