Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>For a six second long press, use a <a href="http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UILongPressGestureRecognizer_Class/Reference/Reference.html%23//apple_ref/occ/cl/UILongPressGestureRecognizer" rel="nofollow noreferrer"><code>UILongPressGestureRecognizer</code></a> with its <code>minimumPressDuration</code> property set to 6. </p> <p>Write your own <a href="https://developer.apple.com/library/ios/documentation/EventHandling/Conceptual/EventHandlingiPhoneOS/GestureRecognizer_basics/GestureRecognizer_basics.html" rel="nofollow noreferrer">gesture recognizer</a> (say, <code>LongTappingGestureRecognizer</code>) for continuous tapping for a given period; it shouldn't be too tricky. Give it a property like <code>UILongPressGestureRecognizer</code>'s <code>minimumPressDuration</code> (say, <code>minimumTappingDuration</code>) and a property (say, <code>maximumLiftTime</code>) that determines how long a finger can be lifted off before it's not considered to be a long tapping gesture.</p> <ul> <li>When it first receives <a href="http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIGestureRecognizer_Class/Reference/Reference.html%23//apple_ref/occ/cl/UIGestureRecognizer" rel="nofollow noreferrer"><code>touchesBegan:withEvent:</code></a>, record the time.</li> <li>When it receives <a href="http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIGestureRecognizer_Class/Reference/Reference.html%23//apple_ref/occ/cl/UIGestureRecognizer" rel="nofollow noreferrer"><code>touchesEnded:withEvent:</code></a>, start an <a href="http://developer.apple.com/library/ios/#documentation/cocoa/reference/foundation/Classes/NSTimer_Class/Reference/NSTimer.html" rel="nofollow noreferrer"><code>NSTimer</code></a> (the lift timer) that sends the gesture recognizer a cancel message (e.g. <code>cancelRecognition</code>) after <code>maximumLiftTime</code>. </li> <li>When it receives <code>touchesBegan:withEvent:</code> when there's a start time, cancel the lift timer (if any). </li> <li>The <code>cancelRecognition</code> will transition to the <a href="http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIGestureRecognizer_Class/Reference/Reference.html%23//apple_ref/c/econst/UIGestureRecognizerStateFailed" rel="nofollow noreferrer">failed state</a>.</li> </ul> <p>There are various strategies for handling recognizing when the end of the gesture is reached, after <code>minimumTappingDuration</code>. One is to check in both the <code>touchesBegan:withEvent:</code> and <code>touchesEnded:withEvent:</code> handlers if the difference between the current time and the start time is >= <code>minimumTappingDuration</code>. The problem with this is that it will take longer than <code>minimumTappingDuration</code> to recognize the gesture if the user is tapping slowly and hir finger is down when the <code>minimumTappingDuration</code> is reached. Another approach is to start another NSTimer (the recognition timer) when the first <code>touchesBegan:withEvent:</code> is received, one that will cause transition to the <a href="http://developer.apple.com/library/ios/#documentation/EventHandling/Conceptual/EventHandlingiPhoneOS/GestureRecognizers/GestureRecognizers.html" rel="nofollow noreferrer">recognized state</a> and that is cancelled in <code>cancelRecognition</code>. The tricky thing here is what to do if the finger is lifted when the timer fires. The best approach might be a combination of the two, ignoring the recognition timer if the finger is lifted.</p> <p>There's more to the details, but that's the gist. Basically, it's a long press recognizer that lets the user lift hir finger off the screen for brief periods. You could potentially use just the tapping recognizer and skip the long press recognizer.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload