Document directory
- 4. uiswipegesturerecognizer)
- 5. uirotationgesturerecognizer (finger rotation operation on the screen)
- 6. uilongpressgesturerecognizer (long-pressed gesture)
Uigesturerecognizer is an abstract class that defines the basic behavior of all gestures. It has six sub-classes to process specific gestures:
1. uitapgesturerecognizer (click any number of fingers at Will)
// Number of clicks
Numberoftapsrequired
// Number of fingers
Numberoftouchesrequired
UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] init];[tapGestureRecognizer addTarget:self action:@selector(gestureRecognizerHandle:)];[tapGestureRecognizer setNumberOfTapsRequired:2];[tapGestureRecognizer setNumberOfTouchesRequired:2];[self.view addGestureRecognizer:tapGestureRecognizer];[tapGestureRecognizer release];
2. uipinchgesturerecognizer (two-finger kneading)
// Pinch the fingers. If the value is greater than 1, the distance between the two fingers increases. If the value is smaller than 1, the distance between the two fingers decreases.
Scale
// Speed (acceleration) during finger kneading)
Velocity
UIPinchGestureRecognizer *pinchGestureRecognizer = [[UIPinchGestureRecognizer alloc] init];[pinchGestureRecognizer addTarget:self action:@selector(gestureRecognizerHandle:)];[self.view addGestureRecognizer:pinchGestureRecognizer];[pinchGestureRecognizer release];
3. uipangesturerecognizer (shake or drag)
// Minimum number of fingers
Minimumnumberoftouches
// Maximum number of fingers
Maximumnumberoftouches
UIPanGestureRecognizer *panGestureRecognizer = [[UIPanGestureRecognizer alloc] init];[panGestureRecognizer addTarget:self action:@selector(gestureRecognizerHandle:)];[panGestureRecognizer setMinimumNumberOfTouches:1];[panGestureRecognizer setMaximumNumberOfTouches:5];[self.view addGestureRecognizer:panGestureRecognizer];[panGestureRecognizer release];
4. uiswipegesturerecognizer)
// Number of sliding fingers
Numberoftouchesrequired
// The slide direction of the finger (Up, down, left, right)
Direction
UISwipeGestureRecognizer *swipeGestureRecognizer = [[UISwipeGestureRecognizer alloc] init];[swipeGestureRecognizer addTarget:self action:@selector(gestureRecognizerHandle:)];[swipeGestureRecognizer setNumberOfTouchesRequired:2];[swipeGestureRecognizer setDirection:UISwipeGestureRecognizerDirectionRight];[self.view addGestureRecognizer:swipeGestureRecognizer];[swipeGestureRecognizer release];
5. uirotationgesturerecognizer (finger rotation operation on the screen)
// Orientation. If the value is less than 0, it indicates a clockwise rotation gesture. If the value is greater than 0, it indicates a clockwise rotation gesture.
Rotation
// Rotation Rate
Velocity
UIRotationGestureRecognizer *rotationGestureRecognizer = [[UIRotationGestureRecognizer alloc] init];[rotationGestureRecognizer addTarget:self action:@selector(gestureRecognizerHandle:)];[self.view addGestureRecognizer:rotationGestureRecognizer];[rotationGestureRecognizer release];
6. uilongpressgesturerecognizer (long-pressed gesture)
// Default is 0. The number of full taps required before the press for gesture to be recognized
Numberoftapsrequired
// The number of fingers that need to be long-pressed
Numberoftouchesrequired
// The time for long-pressing, with a minimum value of 0.5 s
Minimumpressduration
// The distance that the finger can move
Allowablemovement
UILongPressGestureRecognizer *longPressGestureRecognizer = [[UILongPressGestureRecognizer alloc] init];[longPressGestureRecognizer addTarget:self action:@selector(gestureRecognizerHandle:)];[longPressGestureRecognizer setMinimumPressDuration:1.0f];[longPressGestureRecognizer setAllowableMovement:50.0];[self.view addGestureRecognizer:longPressGestureRecognizer];[longPressGestureRecognizer release];