Gestures: Click, long Press, rotate, pinch, drag, sweep, sweep direction
////MAINVIEWCONTROLLER.M//ui05_ gesture recognizer////Created by Dllo on 15/8/4.//Copyright (c) 2015 Zhozhicheng. All rights reserved.//#import "MainViewController.h" @interface mainviewcontroller ()@property(nonatomic, retain)Uiimageview*imageview;@property(nonatomic, retain) Uialertview *alertview;@end @implementation mainviewcontroller -(void) dealloc{[_imageview release]; [_alertview release]; [SuperDealloc];} - (void) Viewdidload {[SuperViewdidload];additional setup after loading the view. //uiimageview UIImage*image=[UIImageimagenamed:@"FootRight_03.jpg.jpg"]; Self. ImageView=[[UiimageviewAlloc] initwithimage:image]; Self. ImageView. Frame=cgrectmake ( -, -, -, -); [ Self. ViewAddsubview: Self. ImageView]; [_imageview release];//To open the user interaction of the picture, which is off by default, and also a control that is a label Self. ImageView. userinteractionenabled=YES;//Use of gestures //1. ClickUITapGestureRecognizer *tap=[[uitapgesturerecognizer Alloc] Initwithtarget: SelfAction@selector(tapaction:)];//Set a few clicks to trigger the methodTap. numberoftapsrequired=2;//Set a few fingers to clickTap. numberoftouchesrequired=2;//Add gestures to the corresponding picture[ Self. ImageViewADDGESTURERECOGNIZER:TAP]; [Tap release];//2. Long pressUilongpressgesturerecognizer *longpress=[[uilongpressgesturerecognizer Alloc] Initwithtarget: SelfAction@selector(longpressaction:)];//Set long press to trigger the shortest timeLongpress. Minimumpressduration=2;//user finger distance allowed to move during long pressLongpress. Allowablemovement= $;//Add gestures to the image[ Self. ImageViewAddgesturerecognizer:longpress]; [Longpress release];//3. Rotation //Create a rotating gestureUirotationgesturerecognizer *rotation=[[uirotationgesturerecognizer Alloc] Initwithtarget: SelfAction@selector(rotationaction:)];//Put the gesture on the corresponding image[ Self. ImageViewAddgesturerecognizer:rotation];//Release[Rotation release];//4. Kneading //CreateUipinchgesturerecognizer *pinch=[[uipinchgesturerecognizer Alloc] Initwithtarget: SelfAction@selector(pincheaction:)];//Add to Picture[ Self. ImageViewAddgesturerecognizer:pinch];//Release[Pinch release];//5. Dragging and draggingUipangesturerecognizer *pan=[[uipangesturerecognizer Alloc] Initwithtarget: SelfAction@selector(panaction:)]; [ Self. ImageViewAddgesturerecognizer:pan]; [Pan release];//6. CleaningUiswipegesturerecognizer *swipe=[[uiswipegesturerecognizer Alloc] Initwithtarget: SelfAction@selector(swipeaction:)]; [ Self. ImageViewAddgesturerecognizer:swipe]; [Swipe release];//direction of cleaningSwipe. Direction=uiswipegesturerecognizerdirectionup;//Screen border gesture iOS7.0 after the gesture appears//Uiscreenedgepangesturerecognizer}#pragma mark click Method-(void) Tapaction: (UITapGestureRecognizer *) tap{NSLog(@"Djkdajdo"); Self. ImageView. Image=[UIImageimagenamed:@"Angry_05.jpg"];}#pragma Mark's response method on time-(void) Longpressaction: (Uilongpressgesturerecognizer *) longpress{//long-pressed status//Longpress.state //Long press to eject a uialerview if(! Self. Alertview) { Self. Alertview=[[uialertview Alloc] initwithtitle:@"404"message:@"Error"Delegate Selfcancelbuttontitle:@"Confirm"Otherbuttontitles:Nil,Nil]; [ Self. AlertviewShow]; [_alertview release]; }}#pragma mark rotates the picture by rotating the picture-(void) Rotationaction: (Uirotationgesturerecognizer *) rotarion{//The view that can be added by gesture capture gesture Uiimageview*imageview= (Uiimageview*) rotarion. View;//operation for rotation //Use the Transform property of the view to rotate the viewImageView. Transform=cgaffinetransformrotate (ImageView. Transform, rotarion. Rotation); Rotarion. Rotation=0;}#pragma mark scales the picture by pinching gestures-(void) Pincheaction: (Uipinchgesturerecognizer *) pinche{//Find a view by gesture Uiimageview*imageview= (Uiimageview*) Pinche. View;//Change the size of the picture by transformImageView. Transform=cgaffinetransformscale (ImageView. Transform, Pinche. scale, Pinche. scale); Pinche. scale=1;}#pragma mark moves by dragging gestures to move-(void) Panaction: (Uipangesturerecognizer *) pan{Uiimageview*imageview= (Uiimageview*) Pan. View;//through gestures to get past points CgpointP=[pan Translationinview:imageview];//Set the location of the moveImageView. Transform=cgaffinetransformtranslate (ImageView. TransformP. xP. Y);//To prevent gestures from trying to disappear while operating[Pan Settranslation:cgpointzero Inview:imageview];}how to #pragma mark sweep-(void) Swipeaction: (Uiswipegesturerecognizer *) swipe{if(Swipe. Direction= = Uiswipegesturerecognizerdirectionup) {NSLog(@"Up"); }}- (void) Didreceivememorywarning {[SuperDidreceivememorywarning];//Dispose of any resources, can be recreated.}/ * #pragma mark-navigation//in a storyboard-based application, you'll often want to do a little preparation before navigation-(void) Prepareforsegue: (Uistoryboardsegue *) Segue Sender: (ID) Sender {//Get the new view controller using [Segue Destinationviewcontroller]. Pass the selected object to the new view Controller.} */@end
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
IOS ui05_ gesture Recognizer