iOS gesture Uigesturerecognizer

Source: Internet
Author: User

Uigesturerecognizer is an abstract class that defines the basic behavior of all gestures, and it has 6 subclasses that handle specific gestures:

1.UITapGestureRecognizer (any number of clicks on any finger)

Click Count

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];

2.UIPinchGestureRecognizer (two finger kneading action)

Finger pinch, greater than 1 means that the distance between two fingers becomes larger, less than 1 means that the distance between two fingers is smaller

Scale

Rate (acceleration) of finger pinch action

Velocity

Uipinchgesturerecognizer *pinchgesturerecognizer = [[Uipinchgesturerecognizer alloc] init];

[Pinchgesturerecognizer addtarget:self Action: @selector (Gesturerecognizerhandle:)];

[Self.view Addgesturerecognizer:pinchgesturerecognizer];

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];

4.UISwipeGestureRecognizer (finger swipe on the screen to manipulate gestures)

Number of sliding fingers

Numberoftouchesrequired

Direction of finger sliding (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];

5.UIRotationGestureRecognizer (finger rotation on the screen)

Rotation direction, less than 0 counterclockwise rotation gesture, greater than 0 for clockwise gestures

Rotation

Rotation rate

Velocity

Uirotationgesturerecognizer *rotationgesturerecognizer = [[Uirotationgesturerecognizer alloc] init];

[Rotationgesturerecognizer addtarget:self Action: @selector (Gesturerecognizerhandle:)];

[Self.view Addgesturerecognizer:rotationgesturerecognizer];

6.UILongPressGestureRecognizer (Long press 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 pressed long

Numberoftouchesrequired

Time required for long press, Min. 0.5s

Minimumpressduration

The distance the finger presses to allow movement

Allowablemovement

Uilongpressgesturerecognizer *longpressgesturerecognizer = [[Uilongpressgesturerecognizer alloc] init];

[Longpressgesturerecognizer addtarget:self Action: @selector (Gesturerecognizerhandle:)];

[Longpressgesturerecognizer setminimumpressduration:1.0f];

[Longpressgesturerecognizer setallowablemovement:50.0];

[Self.view Addgesturerecognizer:longpressgesturerecognizer];

iOS gesture Uigesturerecognizer

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.