XCode4.2-use complex touch and gesture UIXXGestureRecognizer

Source: Internet
Author: User

Using Complex touch and gesture Apple's Class with various gesture identifiers, the following uses several gesture identifiers for implementation: Click, sweep, hide, and rotate (shaking is not involved for the moment ). Each gesture has a pop-up window feedback. In ViewController. in the m file, 1-Click Event-(void) foundTap :( UITapGestureRecognizer *) recognizer {UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @ "Hello" message: @ "tapped" delegate: nil cancelButtonTitle: @ "OK" otherButtonTitles: nil]; [alert show];}-(void) viewDidLoad {[super viewDidLoad]; optional * tapRecognizer; // create a tap gesture reader tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget: self action: @ selector (foundTap :)]; // initialize the reader and use the function pointer (method pointer) method for triggering the simultaneous implementation of tapRecognizer. numberOfTapsRequired = 1; // trigger this behavior by the number of objects (1. numberOfTouchesRequired = 1; // The hand index of the Request Response [self. view addGestureRecognizer: tapRecognizer]; // Add the Controller to the corresponding object} follow the steps below to observe the implementation method: create a controller instance -- initialize the instance -- add it to the class Object -- Implement the method (@ selector () in the function pointer ()). [If You Want To obtain the coordinates of a light or sweep gesture, you can add: CGPoint location = [recognizer locationInView: <the view> to be the view name of the gesture reader; location has two parameters x and y] 2-sweep: Next, follow the steps above to perform the sweep: function pointer pointing method:-(void) foundSwipe :( UISwipeGestureRecognizer *) recognizer {UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @ "Hello" message: @ "swiped" delegate: nil cancelButtonTitle: @ "OK" otherButtonTitles: nil] [alert show];} Still viewDidLoad: Using * swipeRecognizer; // create a lightweight scanner swipeRecognizer = [[using alloc] initWithTarget: self action: @ selector (foundSwipe :)]; // The object is initialized and has a function pointer swipeRecognizer. direction = UISwipeGestureRecognizerDirectionRight | uiswipegesturerecognizerdireleft; // move swipeRecognizer to the left or right of the gesture. numberOfTouchesRequired = 1; // Number of scan objects [self. view addGestureRecognizer: swipeRecognizer]; // when adding a controller to an object, you can choose from four directions: uiswipegesturerecognizerdireright/Left/Up/Down. 3-Zhang he: the following method is used to zoom in and out the function pointer:-(void) foundPinch :( UIPinchGestureRecognizer *) recognizer {// note the class NSString * message; double scale; scale = recognizer. scale; // scale (scale, Scale) of the identification device // Use scale in combination with glScalef of openGLES to scale the message = [[NSString alloc] initWithFormat: @ "scale: Scale: % 1.2f, velocity: % 1.2f ", recognizer. scale, recognizer. velocity]; UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @ "Hello" message: message delegate: nil cancelButtonTitle: @ "OK" otherButtonTitles: nil]; [alert show];} In ViewDidLoad: UIPinchGestureRecognizer * pinchReconizer; // create a new Zhang He reader object pinchReconizer = [[zhangalloc] initWithTarget: self action: @ selector (foundPinch)]; // initialize the object [self. view addGestureRecognizer: pinchReconizer]; // Add controller 4-rotate first the Cocoa class uses radians as the unit, and the conversion relationship between degrees and radians: angle = radian * 180/Pi function pointer pointing method:-(void) foundRotation :( UIRotationGestureRecognizer *) recognizer {NSString * message; double rotation; rotation = recognizer. rotation; // return a controller angle // In openGLES, you can use rotation with glRoatef to rotate message = [[NSString alloc] initWithFormat: @ "rotation, Radians: % 1.2f, Velocity: % 1.2f ", recognizer. rotation, recognizer. velocity]; UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @ "Hello" message: message delegate: nil cancelButtonTitle: @ "OK" otherButtonTitles: nil]; [alert show];} viewDidLoad is as follows: Using * rotationRecognizer; // create a rotation gesture controller object rotationRecognizer = [[using alloc] initWithTarget: self action: @ selector (foundRotation :)]; // initialize the object [self. view addGestureRecognizer: rotationRecognizer]; // Add a controller

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.