The uigesturerecognizer of the gesture operation of iOS

Source: Internet
Author: User

I. Overview

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

-(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 this way of identifying different gestures is really a hassle, and you need to do your own calculations to do different gesture resolution. Later...

Apple has given a more convenient way to use Uigesturerecognizer.

Second, Uigesturerecognizer

UIGestureRecognizer基类 is an abstract class , we mainly use its subclass (name contains link, can click to jump to iOS Developer library, see Official document):

    • UITapGestureRecognizer

    • UIPinchGestureRecognizer

    • UIRotationGestureRecognizer

    • UISwipeGestureRecognizer

    • UIPanGestureRecognizer

    • UILongPressGestureRecognizer

从名字上我们就能知道,Tap (TAP), Pinch (pinch), Rotation (rotate), Swipe (sliding, fast moving, is used to monitor the direction of the slide), Pan (drag, slow movement, is used to monitor the amount of offsets), and longpress (Long Press).

For example, you can add a viewdidload function:

Other gesture methods are similar.

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

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

But some gestures are related, what do we do? For example tap and longpress, swipe and Pan, or tap once with tap twice.

gesture recognition is a principle of mutual exclusion , such as clicking and double-clicking, and if it recognizes a gesture, then the gesture will not be recognized . So for associated gestures, to do special processing to help the program to identify, you should put the current gesture into which type of gesture.

For example, when clicking and double-clicking coexist, it can only send a clicked message if it is not processed. To be able to recognize the double-tap gesture, you need to make a special processing logic, that is, to determine whether the gesture is a double-click, in the case of double-clicking failure as a gesture processing. Use

[a requiregesturerecognizertofail:b] function, which can specify that when a gesture occurs, even if a is satisfied, it will not be triggered immediately and will wait until The specified gesture B is not triggered until it is determined to fail.

Iii. approximate types of iphone operating gestures

1. Tap (TAP)
Click as the most commonly used gesture to press or select a control or entry (similar to a normal mouse click),

2. Drag (Drag)
Drag to implement scrolling of some pages, as well as the movement of controls.

3. Slide (Flick)
Swipe for the ability to quickly scroll and page through pages.

4. Sweep (Swipe)
Sweep gesture the shortcut menu for activating list items

5. Double click (double tap)
Double-click to zoom in and center the picture, or restore the original size (if it is currently zoomed in). Also, double-click to activate the Edit menu for text.

6. Zoom in (Pinch Open)
Zooming in gestures enables you to open a feed and open the details of the article. Magnification gestures can also be used to enlarge a picture when viewed in a photo.

7. Zoom Out (Pinch close)
To zoom out, you can implement features that are reversed and correspond to the magnification gesture: turn off the feed to exit to the first page, and close the article to the index. When you view a photo, the zoom out gesture also allows you to zoom out of the image.

8. Long press (Touch &hold)
On my Subscriptions page, long press feeds will automatically go into edit mode, while selecting the feeds that your finger is currently pressing. You can then drag the feed to move the location directly.
With the long press on the text, the Magnifier accessibility feature appears. When released, the Edit menu appears.
Long press on the picture, the Edit menu appears.

9. Shaking (Shake)
Shake gesture, the undo and Redo menu will appear. is primarily for user text input.

The uigesturerecognizer of the gesture operation of iOS

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.