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 represents the gesture that p fingers tapped the screen q times consecutively.
- Input properties: numberOfTaps (q), numberOfFingers (p)
- Output properties: location, touches
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 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 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 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 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.
- Output properties: rotation, velocity
Custom Gesture Recognizers