Pinch gestures
BlackBerry® devices with a touch screen support pinch gestures. Pinch gestures typically zoom in and out of an object on the screen.
A pinch begins when two touch points are detected on the touch screen. A pinch’s focal point is defined as the midpoint between the two initial touch points.
- When two touch points are detected, a TouchGesture.PINCH_BEGIN event occurs. The coordinate points of the focal point of the pinch gesture are stored as TouchEvent.getX(1) and TouchEvent.getY(1). You can access the initial zoom value by invoking TouchGesture.getPinchMagnitude().
- As the user moves one or both touch points, a series of TouchGesture.PINCH_UPDATE events occur. You can access the zoom values during the pinch by invoking TouchGesture.getPinchMagnitude().
- When the user completes the gesture, a TouchGesture.PINCH_END event occurs. You can access the final zoom value by invoking TouchGesture.getPinchMagnitude().
Code sample: Retrieving information about a pinch gesture
This sample demonstrates how to handle a pinch gesture in a screen's touchEvent() method.
protected boolean touchEvent(TouchEvent message)
{
switch(message.getEvent())
{
case TouchEvent.GESTURE:
TouchGesture gesture = message.getGesture();
switch(gesture.getEvent())
{
case TouchGesture.PINCH_END:
Dialog.alert("Focal point: " + message.getX(1)
+ ", " + message.getY(1)
+ "\nFinal zoom value: " + gesture.getPinchMagnitude());
return true;
}
}
return false;
}
Next topic: Enable pinch gestures