Deprecated: trim(): Passing null to parameter #1 ($string) of type string is deprecated in /var/www/html/extensions/Variables/includes/ExtVariables.php on line 198
UIGestureRecognizer - iPhone Development Wiki

UIGestureRecognizer

From iPhone Development Wiki
Revision as of 00:03, 7 October 2013 by Britta (talk | contribs) (linking SBGestureRecognizer)

UIGestureRecognizer is an abstract class that provides an object-oriented way to add actions to different gestures. It becomes a documented class since firmware 3.2. See also: SBGestureRecognizer.

The typical code that adds a gesture recognizer is

UIGestureRecognizer* rec = [[UIGestureRecognizer alloc] initWithTarget:self action:@selector(touchChangedWithGestureRecognizer:)];
// set options for this recognizer.
[view addGestureRecognizer:rec];
[rec release];

Built-in Gesture Recognizers

UITapGestureRecognizer

UITapGestureRecognizer represents the gesture that p fingers tapped the screen q times consecutively.

  • Input properties: numberOfTaps (q), numberOfFingers (p)
  • Output properties: location, touches

UIPinchGestureRecognizer

UIPinchGestureRecognizer represents the gesture that 2 fingers moving towards or away from a center point. This gesture is usually used for scaling a view.

  • Input properties: scaleThreshold
  • Output properties: scale, velocity, anchorPoint, transform

scaleThreshold is the critical scale the fingers must first move apart/together before this recognizer could fire.

UILongPressGestureRecognizer

UILongPressGestureRecognizer represents the gesture that p fingers moved/stayed on the screen continuously for T seconds. Optionally, numberOfTapsRequired may be specified to require a tap-tap/hold pattern.

  • Input properties: numberOfTapsRequired, numberOfFingers (p), delay (T), allowableMovement
  • Output properties: touches, centroid, startPoint

UIDragRecognizer

UIDragRecognizer represents the gesture that 1 or more fingers moving on the screen for a distance of d. Optionally it may also be constrained to moving only within an angle of θ ± Δθ.

  • Input properties: minimumDistance (d), angle (θ), maximumDeviation (Δθ), restrictsToAngle
  • Output properties: touch, startPosition, startAngle

Note that the angles are in radians.

UIPanGestureRecognizer

UIPanGestureRecognizer represents the gesture that 1 or more fingers moving on the screen for a relatively large distance. This gesture is usually used for scrolling, and is used by UIScroller and UIScrollView.

  • Input properties: directionalLockEnabled
  • Output properties: offset, velocity, transform

UITapAndAHalfRecognizer

UITapAndAHalfRecognizer represents the gesture that 1 finger tapped the screen q times consecutively, and then moved/stayed on the screen.

  • Input properties: numberOfFullTaps (q), allowableMovement
  • Output properties: touch

Note: UITapAndAHalfRecognizer is a private, undocumented class. UILongPressGestureRecognizer should be used instead; UITapAndAHalfRecognizer's numberOfFullTaps requires is equivalent to UILongPressGestureRecognizer's numberOfTapsRequired.

UIRotationGestureRecognizer

UIRotationGestureRecognizer TODO

  • Output properties: rotation, velocity

UISwipeGestureRecognizer

  • TODO.

Custom Gesture Recognizers

  • TODO.

References