Class: SC.SwipeGesture


Extends SC.Gesture.

Defined in: swipe_gesture.js

Field Summary

Instance Methods

Field Detail

Deprecated: Version 1.11. Please use the `angles` property instead.
direction Array
Default value:
SC.SWIPE_HORIZONTAL
name String
Default value:
"swipe"
swipeDistance Number

The distance in pixels that touches must move in a single direction to be far enough in order to be considered a swipe. If the touches don't move swipeDistance amount of pixels, then the gesture will not trigger.

Default value:
40
swipeVelocity Number

The velocity in pixels per millisecond that touches must be traveling to begin a swipe motion. If the touches are moving slower than the velocity, the swipe start point won't be set.

Default value:
0.5
tolerance Number
Amount of degrees that a touch is allowed to vary off of the target angle(s).
Default value:
15

Instance Method Detail

angles(key, value)

The angles that the swipe will accept, between 0° and ±180°. The angles start from the right side (0°) and end at the left side (±180°). With the positive angles passing through down (+90°) and the negative angles passing through up (-90°). The following ASCII art shows the directions of the angles,

-90° (up)
                  |
                  |
(left) ± 180° --------- 0° (right)
                  |
                  |
         (down) +90°

To make this easier, there are several predefined angles arrays that you can use, SC.SWIPE_HORIZONTAL ([180, 0]), i.e. left or right SC.SWIPE_VERTICAL ([-90, 90]), i.e. up or down SC.SWIPE_ANY (null), i.e. 0° to up, down, left or right SC.SWIPE_LEFT ([180]), i.e. left only SC.SWIPE_RIGHT ([0]), i.e. right only SC.SWIPE_UP ([-90]), i.e. up only SC.SWIPE_DOWN ([90]), down only

However, you can provide any combination of angles that you want. For example, to support 45° angled swipes to the right and straight swipes to the left, we would use,

angles: [180, -45, 45] // 180° straight left, -45° up & right, 45° down & right

How to use the angles.

When the swipe event fires, the angle of the swipe is passed to your view allowing you to recognize which of the supported angles matched the swipe.

Note, there is one special case, as defined by SC.SWIPE_ANY, which is to set angles to null in order to support swipes in any direction. The code will look for a swipe (unidirectional fast motion) in any direction and pass the observed angle to the swipe handler.

Parameters:
key
value
touchAddedToSession(touch, touchesInSession)

The swipe gesture is always interested in a touch session, because it is only concerned in how the session ends. If it ends with a fast unidirectional sliding movement, then it is a swipe.

Note, that for multiple touches, touches are expected to start while other touches are already moving. When touches are added we update the swipe start position. This means that inadvertent taps that occur while swiping could break a swipe recognition by making the swipe too short to register.

Parameters:
touch SC.Touch
The touch to be added to the session.
touchesInSession Array
The touches already in the session.
Returns:
Boolean
True as long as the new touch doesn't start too late after the first touch.
See:
SC.Gesture#touchAddedToSession
touchCancelledInSession(touch, touchesInSession)

The swipe gesture is always interested in a touch session, because it is only concerned in how the session ends. If it ends with a fast unidirectional sliding movement, then it is a swipe.

Note, that a touch may cancel while swiping (went off screen inadvertently). Because of this we don't immediately reduce the number of touches in the swipe, because if the rest of the touches end right away in a swipe, it's best to consider the cancelled touch as part of the group.

Parameters:
touch SC.Touch
The touch to be removed from the session.
touchesInSession Array
The touches in the session.
Returns:
Boolean
True
See:
SC.Gesture#touchCancelledInSession
touchEndedInSession(touch, touchesInSession)

The swipe gesture is always interested in a touch session, because it is only concerned in how the session ends. If it ends with a fast unidirectional sliding movement, then it is a swipe.

Note, that touches are expected to end while swiping. Because of this we don't immediately reduce the number of touches in the swipe, because if the rest of the touches also end right away in a swiping motion, it's best to consider this ended touch as part of the group.

Parameters:
touch SC.Touch
The touch to be removed from the session.
touchesInSession Array
The touches in the session.
Returns:
Boolean
True if it is the first touch to end or a subsequent touch that ends not too long after the first touch ended.
See:
SC.Gesture#touchEndedInSession
touchesMovedInSession(touchesInSession)

The swipe gesture is always interested in a touch session, because it is only concerned in how the session ends. If it ends with a fast unidirectional sliding movement, then it is a swipe.

Parameters:
touchesInSession Array
All touches in the session.
Returns:
Boolean
True as long as none of the touches have moved too far off-axis to be a clean swipe.
See:
SC.Gesture#touchesMovedInSession
touchSessionCancelled()
Cleans up all touch session variables.
Returns:
void
See:
SC.Gesture#touchSessionCancelled
touchSessionEnded()
Cleans up all touch session variables and triggers the gesture.
Returns:
void
See:
SC.Gesture#touchSessionEnded
touchSessionStarted(touch)
Parameters:
touch
Documentation generated by JsDoc Toolkit 2.4.0 on Wed Apr 08 2015 10:02:21 GMT-0600 (CST)