How to Use the iOS gesture UIGestureRecognizer

Source: Internet
Author: User
Tags in degrees

The UIKit contains the UIGestureRecognizer class, which is used to detect gestures that occur on the device. UIGestureRecognizer is an abstract class that defines the basic behavior of all gestures. It has the following sub-classes used to process specific gestures: 1. Attach UITapGestureRecognizer (any number of hits) 2. Zoom in or out (used for scaling) 3. Shake or drag UIPanGestureRecognizer 4. Slide UISwipeGestureRecognizer (in any direction) 5. Rotate UIRotationGestureRecognizer (fingers move in the opposite direction) 6. UILongPressGestureRecognizer has different configuration attributes for different types of gesture identifiers. For example, UITapGestureRecognizer can configure the number of hits. After receiving a gesture, the interface can send a message to process the task after responding to the gesture action. Of course, different gesture identifiers send different message methods. The following code is a few examples: one finger, two-click gestures // create a gesture identification device UITapGestureRecognizer * oneFingerTwoTaps = [[UITapGestureRecognizer alloc] initWithTarget: self action: @ selector (oneFingerTwoTaps)] autorelease]; // Set required taps and number of touches [oneFingerTwoTaps setNumberOfTapsRequired: 2]; [oneFingerTwoTaps limit: 1]; // Add the gesture to the view [[self view] addGestureRecognizer: oneFingerTwoTaps]; message method oneFingerTwoTaps-(void) oneFingerTwoTaps {NSLog (@ "Action: One finger, two taps ");} two fingers, shoot two gestures UITapGestureRecognizer * twoFingersTwoTaps = [[UITapGestureRecognizer alloc] initWithTarget: self action: @ selector (twoFingersTwoTaps)] orautelaps]; [Handle latency: 2]; [twoFingersTwoTaps latency: 2]; [self view] latency: twoFingersTwoTaps]; message method twoFingersTwoTaps-(void) twoFingersTwoTaps {NSLog (@ "Action: two fingers, two taps ");} one finger slides up and down. // the slider slides up. * oneFingerSwipeUp = [[[UISwipeGestureRecognizer alloc] initWithTarget: self action: @ selector (oneFingerSwipeUp :)] autorelction]; [oneFingerSwipeUp setDirection: enabled]; [[self view] failed: oneFingerSwipeUp];-(void) oneFingerSwipeUp :( callback *) recognizer {CGPoint point = [recognizer locationInView: [self view]; NSLog (@ "Swipe up-start location: % f, % f", point. x, point. y);} // slide downward ** oneFingerSwipeDown = [[using alloc] initWithTarget: self action: @ selector (oneFingerSwipeDown :)] autorelease]; [using setction ction: direction]; [[self view] addGestureRecognizer: oneFingerSwipeDown];-(void) oneFingerSwipeDown :( optional *) recognizer {CGPoint point = [recognizer locationInView: [self view]; NSLog (@ "Swipe down-start location: % f, % f", point. x, point. y);} rotation gesture rotate * twoFingersRotate = [[using alloc] initWithTarget: self action: @ selector (twoFingersRotate :)] autorelease]; [[self view] rotate: twoFingersRotate]; -(void) twoFingersRotate :( UIRotationGestureRecognizer *) recognizer {// Convert the radian value to show the degree of rotation NSLog (@ "Rotation in degrees since last change: % f ", [recognizer rotation] * (180/M_PI);} refers to the internal or external pinch gesture UIPinchGestureRecognizer * twoFingerPinch = [[UIPinchGestureRecognizer alloc] initWithTarget: self action: @ selector (twoFingerPinch :)] autorelscale]; [[self view] addGestureRecognizer: twoFingerPinch];-(void) twoFingerPinch :( interval *) recognizer {NSLog (@ "Pinch scale: % f ", recognizer. scale);} UITapGestureRecognizer * twoFingersTwoTaps = [[using alloc] initWithTarget: self action: @ selector (listener)] autorelease]; [twoFingersTwoTaps limit: 2]; [twoFingersTwoTaps limit: 2]; [[self view] Methods: twoFingersTwoTaps]; message method twoFingersTwoTaps-(void) twoFingersTwoTaps {NSLog (@ "Action: Two fingers, two taps ");}

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.