Game Development Reference
In-Depth Information
We have looked in detail at the different configurations available for UITapGestureRecognizer .
The following section will explore a new one: the pinch.
Pinch Gestures
Pinch gestures show up in iOS usually as a way of zooming in and out or scaling something on the
screen. This gesture is started by placing two fingers down and then by moving them either toward
each other or away. Figure 8-3 shows this gesture in action.
Figure 8-3. Pinch gesture changing the size of a saucer
In Figure 8-3 , we see our example of using pinch gestures. On the left, the saucer is scaled up as
the result of a pinch-out gesture. On the right we see the same saucer scaled down as the result of a
pinch-in gesture. As the saucer is being scaled, it stops spinning. We take advantage of the different
states of the pinch gesture to stop and start the spinning.
A pinch gesture can be detected by adding an instance of UIPinchGestureRecognizer to a UIView .
A UIPinchGestureRecognizer will not only inform you when a pinch gesture occurs but will also
report a scale and velocity value associated with the gesture. Having the scale reported by a
UIPinchGestureRecognizer is very handy because this is such a common use of the pinch gesture.
This example is implemented in the class PinchGestureController . Let's take a quick look at the
header file, as shown in Listing 8-14.
 
Search WWH ::




Custom Search