Use of ios--gesture control

Source: Internet
Author: User

Gesture recognition is a principle of mutual exclusion, such as clicking and double-clicking, if it recognizes a gesture, the subsequent gesture will not be recognized

Add a click Gesture uitapgesturerecognize

UITapGestureRecognizer *tapgesturerecognizer = [[UITapGestureRecognizer alloc] init];

[Tapgesturerecognizer addtarget:self Action: @selector (tapgestureaction:)];//How to add a click gesture

[Self.view Addgesturerecognizer:tapgesturerecognizer]; Add to Current View

Add a double-tap gesture uitapgesturerecognize

UITapGestureRecognizer *tapgesturerecognizer = [[UITapGestureRecognizer alloc] init];

tapgesturerecognizer.numberoftapsrequired = 2; Set a few clicks to trigger the method

[Tapgesturerecognizer addtarget:self Action: @selector (tapgestureaction:)];//How to add a click gesture

[Self.view Addgesturerecognizer:tapgesturerecognizer]; Add to Current View

Add a long-pressed gesture Uilongpressgesturerecognizer

Note: A two-time method is called that starts a long press call once released and then called once while long pressing and sliding, the long press method is called multiple times

Uilongpressgesturerecognizer *presslonggesturerecognizer = [[Uilongpressgesturerecognizeralloc] init];

[Presslonggesturerecognizer addtarget:self Action: @selector (presslonggestureaction:)];//Add a method to a long press gesture

[Self.view Addgesturerecognizer:presslonggesturerecognizer]; Add to Current View

Add a pinch gesture Uipinchgesturerecognizer

Note: The pinch gesture is not a kneading call method at a time, but rather a constant call to the method during the kneading process.

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

[Pinchgesturerecognizer addtarget:self Action: @selector (pinchgestureaction:)];//How to add a pinch gesture

[Self.view Addgesturerecognizer:pinchgesturerecognizer]; Add to Current View

Add a rotated gesture Uirotationgesturerecognizer

Note: The rotation gesture is rotated at the same time by two fingers

Uirotationgesturerecognizer *rotationgesturerecognizer = [[Uirotationgesturerecognizeralloc] init];

[Rotationgesturerecognizer addtarget:self Action: @selector (rotationgestureaction:)];//Add a method to a rotation gesture

[Self.view Addgesturerecognizer:rotationgesturerecognizer]; Add to Current View

Add a swipe gesture (swipe gesture) Uiswipegesturerecognizer

Note: Fast moving, is used to monitor the direction of the slide

Uiswipegesturerecognizer *swipgesturerecognizer = [[Uiswipegesturerecognizer alloc] init];

Swipgesturerecognizer.direction = Uiswipegesturerecognizerdirectionup; Ways to add gestures

Here is the direction of setting the slide

typedef ns_options (Nsuinteger, uiswipegesturerecognizerdirection) {

Uiswipegesturerecognizerdirectionright = 1 << 0,//swipe from left to right

Uiswipegesturerecognizerdirectionleft = 1 << 1,//swipe from right to left

Uiswipegesturerecognizerdirectionup = 1 << 2,//swipe up from the bottom

Uiswipegesturerecognizerdirectiondown = 1 << 3//swipe from top down

// };

[Swipgesturerecognizer addtarget:self Action: @selector (swipgestureaction:)];//Add a method to a swipe gesture

[Self.view Addgesturerecognizer:swipgesturerecognizer]; Add to Current View

Add a drag gesture (panning gesture) Uipangesturerecognizer

Note: Slow movement, which is used to monitor the amount of offsets

Uipangesturerecognizer *pangesturerecognizer = [[Uipangesturerecognizer alloc] init];

[Pangesturerecognizer addtarget:self Action: @selector (pangestureaction:)];//Add a way to pack and remove

[Self.view Addgesturerecognizer:pangesturerecognizer]; Add to Current View

[Pangesturerecognizer release], Pangesturerecognizer = nil; Freeing memory

#pragma mark-How to implement a click gesture

-(void) Tapgestureaction: (UITapGestureRecognizer *) Sender {

NSLog (@ "You tapped the screen");

}

#pragma mark-How to implement a long-press gesture

-(void) Presslonggestureaction: (Uilongpressgesturerecognizer *) Sender {

NSLog (@ "You have long pressed the screen");

}

#pragma mark-a way to make a pinch gesture

-(void) Pinchgestureaction: (Uipinchgesturerecognizer *) Sender {

NSLog (@ "You pinch the screen");

}

#pragma mark-How to implement a rotational gesture

-(void) Rotationgestureaction: (Uirotationgesturerecognizer *) Sender {

NSLog (@ "You use a rotating gesture");

}

#pragma mark-How to implement a swipe gesture

-(void) Swipgestureaction: (Uiswipegesturerecognizer *) Sender {

NSLog (@ "You swipe the screen");

}

#pragma mark-a way to implement a support gesture

-(void) Pangestureaction: (Uipangesturerecognizer *) Sender {

NSLog (@ "You have moved .... ");

}

Shaking gestures

-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (nsdictionary*) launchOptions

{

Application.applicationsupportsshaketoedit = YES;

return YES;

}

-(BOOL) Canbecomefirstresponder {

return YES;

}

-(void) Viewdidappear: (BOOL) Animated {

[Super viewdidappear:animated];

[Self becomefirstresponder];

}

-(void) Viewwilldisappear: (BOOL) Animated {

[Self resignfirstresponder];

[Super viewwilldisappear:animated];

}

-(void) motionended: (uieventsubtype) Motion withevent: (uievent *) event

{

if (motion = = Uieventsubtypemotionshake) {

NSLog (@ "Shake detected");

}

}

Use of ios--gesture control

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.