Advanced UI-gesture recognition

Source: Internet
Author: User

In order to complete gesture recognition, it is necessary to use the gesture recognizer----Uigesturerecognizer to utilize Uigesturerecognizer, Easily identify some common gestures that users make on a view Uigesturerecognizer is an abstract class that defines the basic behavior of all gestures and uses its subclasses to handle specific gestures UITapGestureRecognizer (percussion) Uipinchgesturerecognizer (pinch, for zooming) Uipangesturerecognizer (drag) Uiswipegesturerecognizer (swipe) Uirotationgesturerecognizer (rotate) Uilongpressgesturerecognizer (long Press) gesture recognition status:
1 typedef ns_enum (Nsinteger, uigesturerecognizerstate) {2     //No touch event occurs, default state of all gesture recognition3 uigesturerecognizerstatepossible,4     //when a gesture has started but has not changed or completed5 Uigesturerecognizerstatebegan,6     //Gesture State Change7 uigesturerecognizerstatechanged,8     //Gesture Completion9 uigesturerecognizerstateended,Ten     //gesture cancellation, revert to possible state One uigesturerecognizerstatecancelled, A     //gesture failed to revert to possible state - uigesturerecognizerstatefailed, -     //recognition to gesture recognition theuigesturerecognizerstaterecognized =uigesturerecognizerstateended -};
Each gesture recognizer uses a similar set of steps, such as UITapGestureRecognizer:
1 //To create a gesture recognizer Object2UITapGestureRecognizer *tap =[[UITapGestureRecognizer alloc] init];3 //to set the specific properties of a gesture Recognizer object4 //2 consecutive Strokes5tap.numberoftapsrequired =2;6 //It takes 2 fingers to tap together .7tap.numberoftouchesrequired =2;8 //add a gesture recognizer to the corresponding view9 [Self.iconview Addgesturerecognizer:tap];Ten //triggering of a listening gesture One[Tap addtarget:self Action: @selector (Tapiconview:)];

Percussion gesture--uitapgesturerecognizer
① tapping Gesture Object related properties
1 @property (nonatomic) Nsuinteger  // number of strokes, default is 12 @property (nonatomic) Nsuinteger  numberoftouchesrequired;   multiple Tap, default is 1
② Proxy Method "implement left half to receive touch events"
1 -(BOOL) Gesturerecognizer: (Uigesturerecognizer *) Gesturerecognizer Shouldreceivetouch: (Uitouch *) touch; // whether to accept touch events
Long-Press gesture--uilongpressgesturerecognizer
Long-Press gesture object-related properties
1 //  2/// touch Point How far around the distance within the long press is valid, by default is (Cgpoint)
Swipe gesture--uiswipegesturerecognizer
Swipe gesture object-related properties
1 // the direction of the swipe is an enumerated type
1 typedef ns_options (Nsuinteger, uiswipegesturerecognizerdirection) {2Uiswipegesturerecognizerdirectionright =1<<0,//Swipe to the right, swipe right by default3Uiswipegesturerecognizerdirectionleft =1<<1,//Swipe left4Uiswipegesturerecognizerdirectionup =1<<2,//Swipe up5Uiswipegesturerecognizerdirectiondown =1<<3//Swipe down6};
Pinch gesture--uipinchgesturerecognizer
Pinch Gesture object related properties
1 @property (nonatomic)          // scaling, is a cumulative process, if you want to not accumulate, the scale is set to 1 2// Example: 3 -(void) Pinvhview: (Uipinchgesturerecognizer *) Pinch {4     Self.pinView.transform = Cgaffinetransformscale (self.pinview.transform,pinch.scale,pinch.scale); 5     1 ; 6 }

Rotation gesture--uirotationgesturerecognizer
① rotation Gesture Object related properties
1 @property (nonatomic)          cgfloat rotation;  // rotation angle, is also an accumulation of the process, if you want it not to accumulate, set it to 0.  2// example 3 -(void) Rotationview: (Uirotationgesturerecognizer *  ) Pinch {4     self.pinView.transform = cgaffinetransformrotate (self.pinView.transform, pinch.rotation); 5     0 ; 6 }
② If you want to use both pinch and rotate, set up a proxy for one gesture and implement a proxy method
1 -(BOOL) Gesturerecognizer: (Uigesturerecognizer *) Gesturerecognizer Shouldrecognizesimultaneouslywithgesturerecognizer: (Uigesturerecognizer *) Othergesturerecognizer; // implement this method, return Yes, allow to occur with other gestures

Drag and drop gestures--uipangesturerecognizer

Drag-and-drop gesture object-related methods and properties:
1@property (nonatomic) Nsuinteger minimumnumberoftouches;//default is 1. The minimum number of touches required to match2@property (nonatomic) Nsuinteger maximumnumberoftouches;//default is Uint_max. The maximum number of touches so can be down3 4-(Cgpoint) Translationinview: (UIView *) view;//translation in the coordinate system of the specified view5- (void) Settranslation: (cgpoint) Translation InView: (UIView *) view;6 7-(Cgpoint) Velocityinview: (UIView *) view;//Velocity of the pan in Pixels/second in the coordinate system of the specified view

Advanced UI-gesture recognition

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.