Class: SC.SwipeGesture
Extends
SC.Gesture.
Defined in: swipe_gesture.js
Field Summary
- direction Deprecated
- name
- swipeDistance
- swipeVelocity
- tolerance
Instance Methods
- angles(key, value)
- touchAddedToSession(touch, touchesInSession)
- touchCancelledInSession(touch, touchesInSession)
- touchEndedInSession(touch, touchesInSession)
- touchesMovedInSession(touchesInSession)
- touchSessionCancelled()
- touchSessionEnded()
- touchSessionStarted(touch)
Field Detail
- Default value:
- SC.SWIPE_HORIZONTAL
- Default value:
- "swipe"
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
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
- Default value:
- 15
Instance Method Detail
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
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
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
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
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
- Returns:
- void
- See:
- SC.Gesture#touchSessionCancelled
- Returns:
- void
- See:
- SC.Gesture#touchSessionEnded
- Parameters:
- touch