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 );}