An analysis of the uigesturerecognizer of IOS ' gesture operation (recommended) _ios

Source: Internet
Author: User
Tags touch

I. Overview

The iphone handles touch screen operation, before 3.2 is mainly used by the uiresponder of the following 4 ways:

 -(void) Touchesbegan: (Nsset *) touches withevent: (Uievent *) event
 -(void) touchescancelled: (Nsset *) touches Withevent: (uievent *) event
 -(void) touchesended: (Nsset *) touches withevent: (Uievent *) event
 -(void) Touchesmoved: (Nsset *) touches withevent: (Uievent *) event

But in this way, it is troublesome to discriminate between different gestures, and you need to compute your own gestures to distinguish between them. Later...

Apple gives a simpler way to use Uigesturerecognizer.

Second, Uigesturerecognizer

The Uigesturerecognizer base class is an abstract class, and we mainly use its subclasses (name contains links, can click to skip to iOS Developer Library, see official documents):

    1. UITapGestureRecognizer
    2. Uipinchgesturerecognizer
    3. Uirotationgesturerecognizer
    4. Uiswipegesturerecognizer
    5. Uipangesturerecognizer
    6. Uilongpressgesturerecognizer

From the name we can know, tap (tap), Pinch (kneading), rotation (rotate), swipe (sliding, fast moving, is used to monitor the direction of the slide), Pan (drag, slow move, is used to monitor the amount of offset) and longpress (Long Press).

For example, you can add in the Viewdidload function:

-(void) viewdidload 
{ 
 [super viewdidload]; 
 Do no additional setup after loading the view from its nib. 
 Uipangesturerecognizer *panrecognizer = [[Uipangesturerecognizer alloc] initwithtarget:self action: @selector ( Handlepanfrom:)]; 
 [Self.view addgesturerecognizer:panrecognizer];//Key statement, add a gesture monitor to Self.view; 
 panrecognizer.maximumnumberoftouches = 1; 
 Panrecognizer.delegate = self; 
 [Panrecognizer release]; 

Other gesture methods are similar.

The core is to set up delegate and use Addgesturerecognizer to add specified gesture monitoring on view that requires gesture monitoring.

Of course remember to add <UIGestureRecognizerDelegate> to the header file as a delegate view.

But some gestures are related, how to do? For example, tap and longpress, swipe and Pan, or tap once and tap twice.

Gesture recognition is a principle of mutual exclusion, such as clicking and double-clicking, and if it identifies a gesture, subsequent gestures will not be recognized. Therefore, for the associated gesture, special treatment is needed to help the program to identify, should be the current gesture into what kind of gesture inside.

For example, when a click and double-click Coexist, it can only send out a clicked message if it is not processed. In order to be able to recognize the double gesture, you need to do a special processing logic, that is, first to determine whether the gesture is a double click, in the case of double-click failure as a click gesture processing. Use
[A requiregesturerecognizertofail:b] function, which specifies that when a gesture occurs, even if a is already satisfied, it does not trigger immediately, until the specified gesture B is determined to fail.

Three, the iphone operation gesture of the approximate type

1. Click (TAP)

Click as the most commonly used gesture to press or select a control or entry (similar to normal mouse clicks),

2. Drag (Drag)

Drag to implement the scrolling of some pages and the ability to move controls.

3. Slide (Flick)

Sliding is used to implement the page's fast scrolling and paging function.

4. Sweep (swipe)

Sweeping gestures quick Action menu for activating list items

5. Double click (Double Tap)

Double-click to enlarge and center the picture, or restore the original size (if it is currently enlarged). Also, double-click to activate the menu for text editing.

6. Enlarge (Pinch Open)

Zooming in can do the following: Open the feed and open the details of the article. When the photos are viewed, the enlarged gestures also enable the image to be enlarged.

7. Zoom Out (Pinch close)

Reduce gestures, you can achieve the opposite of the amplification gesture and the corresponding function function: Close the feed exit to the home page, close the article exit to the index page. When the photo is viewed, narrowing the gesture can also reduce the image's function.

8. Long press (Touch &hold)

On my subscription page, a long press feed will automatically enter edit mode, while selecting the feed that the finger is currently pressing. At this point, you can drag the feed move location directly.

Magnifier accessibility will appear for text long press. When it is released, the Edit menu appears.

The Edit menu appears for the long press of the picture.

9. Shaking (Shake)

The shaking gesture will appear with the Undo and redo menu. is mainly for user text input.

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

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.