Capture, click, and screen draw gestures for iOS development (68)

Source: Internet
Author: User

 

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.