Game Development Reference
In-Depth Information
UISwipeGestureRecognizer
UIPanGestureRecognizer
UILongPressGestureRecognizer
In Listing 8-6, we see each subclass of UIGestureRecognizer that is built into iOS 6. Tap is probably
the most common gesture in iOS , and needs no description. The pinch gesture is when two fingers
either move closer or farther away from each other. The rotation gesture is when two fingers move
on the screen like you are opening a bottle of ketchup. The swipe gesture is when one or more
fingers are flicked across the screen, as if turning a page in a magazine. The pan gesture is similar
to swipe, but slower and more deliberate. The long press gesture is much like a tap, but the finger is
held to the screen longer.
Each of these classes provides an easy way for a developer to request that a task be called should
UIView . In addition to calling a task, each gesture
Values for the enum UIGestureRecognizerState
In Listing 8-7, we see the seven possible states for a gesture recognizer to be in, and these
are analogous to four tasks that are called touch events (see Listing 8-1). The default state is
UIGestureRecognizerStatePossible and is the state that all UIGestureRecignizer instances
will be in if no touch events are happening. UIGestureRecognizerStateBegan is the state when
a gesture has started, but not yet changed or completed. For a pinch gesture, this would
be when both fingers have landed on the screen. UIGestureRecognizerStateChanged is the
state of gesture in progress. A gesture will be over when one of the three following states
has occurred: UIGestureRecognizerStateEnded , UIGestureRecognizerStateCancelled , or
UIGestureRecognizerStateFailed . The state UIGestureRecognizerStateEnded corresponds
the successful completion of a gesture. UIGestureRecognizerStateCancelled is the state
of a gesture that cannot be completed. UIGestureRecognizerStateFailed is the state of
a gesture that has received touch events in contradiction to the gesture. The last state,
UIGestureRecognizerStateRecognized , has the same value as UIGestureRecognizerStateEnded
and simply provides a semantic difference that might be useful in code.
While the states in Listing 8-7 provided a comprehensive description of the states a gesture
recognizer can go through, not all gesture recognizers use all of these states. For example,
UITapGestureRecognizer is known as a “discrete” gesture recognizer and does not report changes.
Further, discrete gestures cannot fail or be cancelled. They simply call the selector task once, with
the state of UIGestureRecognizerStateRecognized (e.g., UIGestureRecognizerStateEnded ).
It is possible to implement a new UIGestureRecognizer , but we will not be covering that. We will,
however, take each gesture recognizer and explore how it works with an example.
 
Search WWH ::




Custom Search