Difference between revisions of "UIGestureRecognizer"

From iPhone Development Wiki
Jump to: navigation, search
(Created page with 'UIGestureRecognizer is an abstract class that provides an object-oriented way to add actions to different gestures. The typical code that adds a gesture recognizer is <sourc…')
 
(grammar)
 
(5 intermediate revisions by 4 users not shown)
Line 1: Line 1:
[[UIGestureRecognizer]] is an abstract class that provides an object-oriented way to add actions to different gestures.
+
[[UIGestureRecognizer]] is an abstract class that provides an object-oriented way to add actions to different gestures. It has been a documented class since firmware 3.2. See also: [[SBGestureRecognizer]].
  
 
The typical code that adds a gesture recognizer is
 
The typical code that adds a gesture recognizer is
Line 23: Line 23:
  
 
=== UILongPressGestureRecognizer ===
 
=== UILongPressGestureRecognizer ===
'''UILongPressGestureRecognizer''' represents the gesture that ''p'' fingers moved/stayed on the screen continuously for ''T'' seconds.  
+
'''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'': numberOfFingers (''p''), delay (''T''), allowableMovement
+
* ''Input properties'': numberOfTapsRequired, numberOfFingers (''p''), delay (''T''), allowableMovement
 
* ''Output properties'': touches, centroid, startPoint
 
* ''Output properties'': touches, centroid, startPoint
  
Line 43: Line 43:
  
 
=== UITapAndAHalfRecognizer ===
 
=== UITapAndAHalfRecognizer ===
'''UITapGestureRecognizer''' represents the gesture that 1 finger tapped the screen ''q'' times consecutively, and then moved/stayed on the screen.
+
'''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
 
* ''Input properties'': numberOfFullTaps (''q''), allowableMovement
 
* ''Output properties'': touch
 
* ''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 ===
 
=== UISwipeGestureRecognizer ===

Latest revision as of 00:03, 7 October 2013

UIGestureRecognizer is an abstract class that provides an object-oriented way to add actions to different gestures. It has been 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