1 Preface
Gestures are actually a combination of touch events. gesture event recognition must be added to a uiview class. Multiple gesture identifiers can be added to a single view. Once some gesture actions are captured on this interface, this view will pass the gesture action to other gesture identifiers.
Some touch events require support from the mobile phone system. The following are six gesture identifiers provided by IOS sdk5.
• Swipe // stroke
• Rotation // Rotation
• Pinch // contraction
• Pan // shake
• Long press // long press
• Tap // click
The most basic framework must follow the steps below to process gestures:
Create an object for the appropriate gesture reader.
Binds the object of this gesture identification device to a view.
Add some methods to capture gesture events.
• The return type of this method must be null.
• This method either has no parameter type or can only accept one uigesturerecognizer type parameter.
Gesture Recognition devices can be divided into two categories: one is a separate gesture and the other is a coherent gesture combination. As the name suggests, a gesture is followed by an event that is captured by a listener and then executed accordingly. Consistent is a group of gesture actions, and then listens to capture events for relevant processing. . Consistent is a group of gesture actions, and then listens to capture events for relevant processing.
ReferenceCode
-(Void) taprecognizer :( uitapgesturerecognizer *) paramsender {
/**/
}
-(Void) taprecognizer {
/**/
}
In this section, we will learn about uiswipegesturerecognizer.
2. code example
Zyviewcontroller. m
-(Void) viewdidload {[Super viewdidload]; // do any additional setup after loading the view, typically from a nib. /* instantiate the gesture object */self. swipegesturerecognizer = [[uiswipegesturerecognizer alloc] initwithtarget: Self action: @ selector (handleswipes :)];/* slide from right to left */self. swipegesturerecognizer. direction = uiswipegesturerecognizerdireleft;/* single finger */self. swipegesturerecognizer. numberoftouchesrequired = 1;/* Add to view */[self. view addgesturerecognizer: Self. swipegesturerecognizer];}-(void) handleswipes :( uiswipegesturerecognizer *) paramsender {// press if (paramsender. direction & uiswipegesturerecognizerdirectiondown) {nslog (@ "Swiped down. ");} // left if (paramsender. direction & uiswipegesturerecognizerdireleft) {nslog (@ "Swiped left. ");} // to the right if (paramsender. direction & uiswipegesturerecognizerdireright) {nslog (@ "swiped right. ");} // lift if (paramsender. direction & uiswipegesturerecognizerdireup up) {nslog (@ "Swiped up. ");}}
Running result
Result displayed on the console after you move the cursor from right to left on the simulator Screen
22:22:43. 005 uiswipegesturetest [734: c07] swiped left.
3 conclusion
The above is all content and I hope it will help you.
Demo download: http://download.csdn.net/detail/u010013695/5363763