UIGestureRecognizer gesture operation, uigesturerecognizer

Source: Internet
Author: User

UIGestureRecognizer gesture operation, uigesturerecognizer

UIGestureRecognizer class is used to detect, recognize the gestures used by users when using devices, and define the basic behavior of all gestures. The following is a subclass of UIGestureRecognizer.

Click gesture

Click the gesture UITapGestureRecognizerUITapGestureRecognizer * singleTap = [[UITapGestureRecognizer alloc] initWithTarget: self action: @ selector (singleTap :)]; [self. view addGestureRecognizer: singleTap]; // Click Event-(void) singleTap :( UITapGestureRecognizer *) tapgestrue {NSLog (@ "click ");}


Double-click gesture

UITapGestureRecognizerUITapGestureRecognizer * doubleTap = [[UITapGestureRecognizer alloc] initWithTarget: self action: @ selector (doubleTap :)]; doubleTap. numberOfTapsRequired = 2; [self. view addGestureRecognizer: doubleTap]; // double-click the gesture [singleTap Reset: doubleTap]; // double-click the event-(void) doubleTap :( UITapGestureRecognizer *) taggestrue {NSLog (@ "double-click ");}

Swipe gesture

UISwipeGestureRecognizer * swipeGesture = [[UISwipeGestureRecognizer alloc] initWithTarget: self action: @ selector (swipe :)]; // you can specify the swipe direction. direction = UISwipeGestureRecognizerDirectionDown; [self. view addGestureRecognizer: swipeGesture]; // sweep event-(void) swipe :( UISwipeGestureRecognizer *) swipeGesture {NSLog (@ "sweep gesture ");}

// Translation

UIPanGestureRecognizer * panGesture = [[UIPanGestureRecognizer alloc] initWithTarget: self action: @ selector (pan :)]; [self. view addGestureRecognizer: panGesture]; // pan event-(void) pan :( UIPanGestureRecognizer *) pan {CGPoint point = [pan locationInView: self. view]; NSLog (@ "% @", NSStringFromCGPoint (point ));}

// Long-pressed gesture

UILongPressGestureRecognizer * longPressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget: self action: @ selector (longPress :)]; longPressGesture. minimumPressDuration = 2; [self. view addGestureRecognizer: longPressGesture]; // longPress gesture event-(void) longPress :( UILongPressGestureRecognizer *) longPress {// call it once when Long press leaves, so you need to set the gesture status if (longPress. state = UIGestureRecognizerStateEnded) {return;} NSLog (@ "Long press for more than two seconds ");}

// Rotating gesture

UIRotationGestureRecognizer * rotation = [[UIRotationGestureRecognizer alloc] initWithTarget: self action: @ selector (rotation :)]; [self. view addGestureRecognizer: rotation]; // rotation event-(void) rotation :( UIRotationGestureRecognizer *) rotation {// obtain the float degree = rotation Angle Based on the rotation radians. rotation * (180/M_PI); NSLog (@ "% f", degree );}

 

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.