Common iOS gestures and ios gestures
UIGestureRecognizer encapsulates various iOS gestures to fully meet users' needs for gestures.
The following is a detailed application and description of various gestures, hoping to help you. Pai_^
-(Void) viewDidLoad {[super viewDidLoad]; // Do any additional setup after loading the view. self. view. backgroundColor = [UIColor groupTableViewBackgroundColor]; _ imageView = [[UIImageView alloc] initWithFrame: CGRectMake (self. view. frame. size. width-150)/2, (self. view. frame. size. height-150)/2,150,150)]; _ imageView. userInteractionEnabled = YES; // interactive enabling, allowing interface interaction _ imageView. image = [UIImage imageNamed :@" Cat.png "]; [self. view addSubview: _ imageView]; // click the TapRecognizer UITapGestureRecognizer * singleTap; singleTap = [[delealloc] initWithTarget: self action: @ selector (SingleTap :)]; singleTap. numberOfTapsRequired = 1; // Number of clicks = 1 click [_ imageView addGestureRecognizer: singleTap]; // Add a gesture monitoring to the object; // double-click the TapRecognizer UITapGestureRecognizer * doubleTap = [[UITapGestureRecognizer alloc] initW IthTarget: self action: @ selector (DoubleTap :)]; doubleTap. numberOfTapsRequired = 2; // Number of clicks = 2 double-click [_ imageView addGestureRecognizer: doubleTap]; // Add a gesture monitoring to the object;/* 1. double-click gesture to confirm that the monitoring fails will trigger the corresponding operation of the click gesture. Otherwise, when double-click is performed, the system will respond to the Click Event 2. when you click the button, you need to determine whether it is a double-click. Calling and clicking will be delayed. It is a normal phenomenon. */[SingleTap merge: doubleTap]; // Pinch UIPinchGestureRecognizer * pinch; pinch = [[mongoalloc] initWithTarget: self action: @ selector (handlePinch :)]; // [_ imageView addGestureRecognizer: pinch]; // when adding to _ imageView, you need to put your finger in _ imageView to operate [self. view addGestureRecognizer: pinch]; // when the value is self, you can compress _ imageView (operate in response to the event) pinch for the entire view. delegate = self; // Rotation gesture Rotation UIRotationGestureRecognizer * rotateRecognizer = [[initalloc] initWithTarget: self action: @ selector (handleRotate :)]; [self. view addGestureRecognizer: rotateRecognizer]; // when it is self, you can compress _ imageView (in response to the event) rotateRecognizer to operate the entire view. delegate = self; // sliding gesture SwipeRecognizer UISwipeGestureRecognizer * swipeRecognizer = [[delealloc] initWithTarget: self action: @ selector (handleSwipe :)]; [self. view addGestureRecognizer: swipeRecognizer]; // when it is self, you can compress _ imageView (in response to the event) for the entire view. swipeRecognizer. direction = uiswipegesturerecognizerdireleft; // The operation is left slide swipeRecognizer. delegate = self; // drag the gesture PanRecognizer into * panRecognizer = [[financialloc] initWithTarget: self action: @ selector (handlePan :)]; [_ imageView addGestureRecognizer: panRecognizer] // key statement, add a gesture monitoring; panRecognizer. maximumNumberOfTouches = 1; panRecognizer. delegate = self; // LongPressRecognizer longPressRecognizer gesture * longPressRecognizer = [[financialloc] identifier: self action: @ selector (identifier :)]; [_ imageView identifier: longPressRecognizer]; LongPressRecognizer. minimumPressDuration = 1.0f; // The trigger duration is 1.0 seconds longPressRecognizer. delegate = self;}-(void) SingleTap :( UITapGestureRecognizer *) recognizer {// process the clicked NSLog (@ "Click operation");}-(void) DoubleTap :( UITapGestureRecognizer *) recognizer {// process double-click operation NSLog (@ "double-click operation");}-(void) handlePinch :( UIPinchGestureRecognizer *) recognizer {NSLog (@ "Scaling operation "); // process the zoom operation // scale the image VIEW _ imageview. transform = CGAffineTransformScale (_ imageView. transform, recognizer. scale, recognizer. scale); // to self. view scaling because recognizer is added in self. // recognizer on view. view. transform = CGAffineTransformScale (recognizer. view. transform, recognizer. scale, recognizer. scale); recognizer. scale = 1 ;}- (void) handleRotate :( UIRotationGestureRecognizer *) recognizer {NSLog (@ "rotate operation"); // process rotation operation // rotate _ imageview on imageView. transform = CGAffineTransformRotate (_ imageView. transform, recognizer. rotation); // For self. view rotation because recognizer is added in self. // recognizer on view. view. transform = CGAffineTransformRotate (recognizer. view. transform, recognizer. rotation); recognizer. rotation = 0;}-(void) handleSwipe :( UISwipeGestureRecognizer *) recognizer {// process the sliding operation if (recognizer. direction = uiswipegesturerecognizerdireleft) {NSLog (@ "Slide left operation");} else if (recognizer. direction = direction) {NSLog (@ "slide right operation") ;}}- (void) handlePan :( UIPanGestureRecognizer *) recognizer {NSLog (@ "drag operation "); // process the drag operation. The drag operation is based on the imageview. If the image is rotated, the drag direction is also relative to the top, bottom, and left of the imageview, instead of the screen-to-bottom CGPoint translation = [recognizer translationInView: _ imageView. view. center = CGPointMake (recognizer. view. center. x + translation. x, recognizer. view. center. y + translation. y); [recognizer setTranslation: CGPointZero inView: _ imageView];}-(void) handlelongPress :( UILongPressGestureRecognizer *) recognizer {// processing duration, which is called at the beginning and end, therefore, if (recognizer. state = UIGestureRecognizerStateBegan) {NSLog (@ "Start long-press operation");} else if (recognizer. state = UIGestureRecognizerStateEnded) {NSLog (@ "end long press operation") ;}}-(void) didReceiveMemoryWarning {[super didreceivemorywarning]; // Dispose of any resources that can be recreated .}