Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>On UIPanGestureRecognizer you can use <a href="http://developer.apple.com/library/ios/documentation/uikit/reference/UIPanGestureRecognizer_Class/Reference/Reference.html#//apple_ref/occ/instm/UIPanGestureRecognizer/velocityInView%3a">-velocityInView:</a> to get the velocity of the fingers at the time that gesture was recognised.</p> <p>If you wanted to do one thing on a pan right and one thing on a pan left, for example, you could do something like:</p> <pre><code>- (void)handleGesture:(UIPanGestureRecognizer *)gestureRecognizer { CGPoint velocity = [gestureRecognizer velocityInView:yourView]; if(velocity.x &gt; 0) { NSLog(@"gesture went right"); } else { NSLog(@"gesture went left"); } } </code></pre> <p>If you literally want to detect a reversal, as in you want to compare a new velocity to an old one and see if it is just in the opposite direction — whichever direction that may be — you could do:</p> <pre><code>// assuming lastGestureVelocity is a class variable... - (void)handleGesture:(UIPanGestureRecognizer *)gestureRecognizer { CGPoint velocity = [gestureRecognizer velocityInView:yourView]; if(velocity.x*lastGestureVelocity.x + velocity.y*lastGestureVelocity.y &gt; 0) { NSLog(@"gesture went in the same direction"); } else { NSLog(@"gesture went in the opposite direction"); } lastGestureVelocity = velocity; } </code></pre> <p>The multiply and add thing may look a little odd. It's actually a dot product, but rest assured it'll be a positive number if the gestures are in the same direction, going down to 0 if they're exactly at right angles and then becoming a negative number if they're in the opposite direction.</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.
 

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