Basic gesture Recognition

Source: Internet
Author: User

First, Uigesturerecognizer introduction gestures are often used in iOS, can be said to be very important to exist, before, most of them are through the touch method to determine the gesture, But after iOS system 3.2, Uigesturerecongnizer abstract classes were added and several subclasses were abstracted
    • UITapGestureRecognizer (Point)
    • Uipinchgesturerecognizer (zoom)
    • Uirotationgesturerecognizer (swivel)
    • Uiswipegesturerecognizer (Swipe)
    • Uipangesturerecognizer (drag)
    • Uilongpressgesturerecognizer (Long Press)
These gestures are very simple, basically understand one of the usage, the other will all understand, so we today take the drag as an example, to do a side-by-side expand the menu bar we first to understand the basic usage of these gestures 1, zoom gesture
Uipinchgesturerecognizer *pinchgesturerecognizer = [[Uipinchgesturerecognizer alloc] initwithtarget:self  Action: @selector (handlepinch:)];  [ImageView Addgesturerecognizer:pinchgesturerecognizer];  
callback method
-(void) Handlepinch: (uipinchgesturerecognizer*) recognizer  {      =  Cgaffinetransformscale (Recognizer.view.transform, Recognizer.scale, Recognizer.scale);       1 ;  }  
2. Drag gestures
Uipangesturerecognizer * Panrecognizer = [[Uipangesturerecognizer alloc]initwithtarget:self Action: @selector ( Handlepan:)];    // add gestures to Tabbarcontroller.view   [Tabbarcontroller.view Addgesturerecognizer:panrecognizer];  
callback method
-(void) Handlepan: (uipangesturerecognizer*) recognizer  {      = [recognizer TranslationInView:self.view];       = Cgpointmake (recognizer.view.center.x ++ translation.y);      [Recognizer Settranslation:cgpointzero InView:self.view];        }  
3. Rotating gestures
/* * *   handle rotation gesture  *  *  @param recognizer Rotation gesture Recognizer Object Instance   *   /-(void) Handlerotation: (Uirotationgesturerecognizer *
{ = cgaffinetransformrotate (recognizer.view.transform, recognizer.rotation); 0.0 ; }

It is important to note that a gesture can only correspond to one view, but a view can have multiple gestures

Basic 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.