#import"RootViewController.h"#import"Uicolor+myuicolor.h"@interface Rootviewcontroller () @end @implementation Rootviewcontroller/*UITapGestureRecognizer is a pat? gesture recognizer, can recognize the tap Operation Uilongpressgesturerecognizer is? Long press? Gesture recognizer, can recognize? Long press operation. Uirotationgesturerecognizer is a rotary gesture recognizer that can recognize rotation operations. Uipinchgesturerecognizer is a pinch gesture recognizer that can identify pinch operations. Uipangesturerecognizer is a panning gesture recognizer that can recognize drag and drop operations. Uiswipegesturerecognizer is a swipe gesture recognizer that recognizes drag-and-drop operations. Uiscreenedgepangesturerecognizer is the screen edge swipe recognizer, which is the new in iOS7? gestures. */- (void) viewdidload {[Super viewdidload]; //Do any additional setup after loading the view.UIView *redview = [[UIView alloc] Initwithframe:cgrectmake (0, -, [UIScreen Mainscreen].bounds.size.width, -)]; [Self.view Addsubview:redview]; Redview.backgroundcolor=[Uicolor Redcolor]; [Redview release]; //base class for gesture recognizer: Uigesturerecognizer//Pat gesture /*//Pat gesture//1. Create a tap gesture object UITapGestureRecognizer *tapgesture = [[UITapGestureRecognizer alloc] Initwithtarget:self Action: @selector (handletapgesture:)]; 2. Add a view to the view//set the number of taps tapgesture.numberoftapsrequired = 2; Set the number of touch points tapgesture.numberoftouchesrequired = 2; [Redview addgesturerecognizer:tapgesture]; 3. Release [Tapgesture release]; */ //long-Press gestures /*//1. Creating a long-press gesture object Uilongpressgesturerecognizer *longgesture = [[Uilongpressgesturerecognizer alloc] Initwithtarget:s Elf Action: @selector (handlelongpress:)]; Set the recognition time for long press gestures longgesture.minimumpressduration = 0.3; 2. Add to view [Redview addgesturerecognizer:longgesture]; 3. Release [Longgesture release]; */ //Sweep gesture//1. Create Sweep gestures /*Uiswipegesturerecognizer *swipegestureleft = [[Uiswipegesturerecognizer alloc] initwithtarget:self action:@ Selector (handleswipegesture:)]; 2. Add to view [Redview Addgesturerecognizer:swipegestureleft]; Release [Swipegestureleft release]; Uiswipegesturerecognizer *swipegestureright = [[Uiswipegesturerecognizer alloc] initwithtarget:self action: @selector (handleswipegesture:)]; Set Sweep direction swipegestureright.direction = Uiswipegesturerecognizerdirectionleft; 2. Add to view [Redview addgesturerecognizer:swipegestureright]; Release [Swipegestureright release]; */ //panning gestures//1. Create a panning Gesture objectUipangesturerecognizer *pangesture =[[Uipangesturerecognizer alloc] initwithtarget:self action: @selector (handlepangesture:)]; //2. Add a Gesture object[Redview addgesturerecognizer:pangesture]; //3. Release[Pangesture release]; //pinch gesture /*//1. Creating a pinch gesture uipinchgesturerecognizer *pinchgesture = [[Uipinchgesturerecognizer alloc] initwithtarget:self actio N: @selector (handlepinchgesture:)]; 2. Add to view [Redview addgesturerecognizer:pinchgesture]; 3. Release [Pinchgesture release]; */ //Rotate gestures /*//1. Creating a rotation gesture object uirotationgesturerecognizer *rotationgesture = [[Uirotationgesturerecognizer alloc] Initwithtarget : Self action: @selector (handlerotationgesture:)]; 2. Add to view [Redview addgesturerecognizer:rotationgesture]; 3. Release [Rotationgesture release]; */ //screen edge panning gesture//1. Create the screen edge panning gesture Object//Uiscreenedgepangesturerecognizer *screenedgepan = [[Uiscreenedgepangesturerecognizer alloc] InitWithTarget:self Action: @selector (handelscreenedgegesture:)];// //2. Add a View// //set screen boundaries for panning//screenedgepan.edges = uirectedgeleft;//[Redview Addgesturerecognizer:screenedgepan];// //3. Release the View//[Screenedgepan release];}- (void) didreceivememorywarning {[Super didreceivememorywarning]; //Dispose of any resources the can be recreated.}#pragmaMark----handle Gesture action//Screen Edge gestures- (void) Handelscreenedgegesture: (Uiscreenedgepangesturerecognizer *) screenedge{//1. Get the pan incrementCgpoint point =[Screenedge TranslationInView:screenEdge.view]; //2. Panning the ViewScreenEdge.view.transform = Cgaffinetransformtranslate (ScreenEdge.view.transform, Point.x,0); //3. Clear the previous increment by 0[Screenedge Settranslation:cgpointzero InView:screenEdge.view]; }//Rotate gestures- (void) Handlerotationgesture: (Uirotationgesturerecognizer *) rotationgesture{//Radiation TransformationRotationGesture.view.transform =cgaffinetransformrotate (RotationGesture.view.transform, rotationgesture.rotation); Rotationgesture.rotation=0;}//pinch gesture- (void) Handlepinchgesture: (Uipinchgesturerecognizer *) pinch{//affine transformations//start scaling from the original positionPinch.view.transform =Cgaffinetransformmakescale (Pinch.scale, Pinch.scale); //pinch.view.transform = Cgaffinetransformscale (Pinch.view.transform, Pinch.scale, Pinch.scale);// //Set the previous zoom scale to 1//Pinch.scale = 1;}//panning gestures- (void) Handlepangesture: (Uipangesturerecognizer *) pangesture{// //1. Get the pan increment//cgpoint point = [Pangesture TranslationInView:panGesture.view];// //2. Change the position of the view//panGesture.view.center = cgpointmake (pangesture.view.center.x + point.x, Point.y + pangesture.view.center.y);// // //3. Clear the previous increment by 0//[Pangesture Settranslation:cgpointzero InView:panGesture.view]; //affine transformations//1. Get the pan incrementCgpoint point =[Pangesture TranslationInView:panGesture.view]; //2. Modify the transform of the view//panGesture.view.transform = Cgaffinetransformmakescale (Point.x, POINT.Y); //panGesture.view.transform = cgaffinetransformtranslate (PanGesture.view.transform, Point.x, point.y);PanGesture.view.transform =cgaffinetransformmaketranslation (Point.x, POINT.Y); //3. Clear the previous increment by 0//[Pangesture Settranslation:cgpointzero InView:panGesture.view];}//Sweep gesture- (void) Handleswipegesture: (Uiswipegesturerecognizer *) swipgesture{if(Swipgesture.direction = =uiswipegesturerecognizerdirectionright) {SwipGesture.view.backgroundColor=[Uicolor Randomcolor]; } if(Swipgesture.direction = =uiswipegesturerecognizerdirectionleft) {Self.view.backgroundColor=[Uicolor Randomcolor]; }}//Handle TAP gestures- (void) Handletapgesture: (UITapGestureRecognizer *) tapgesture{TapGesture.view.backgroundColor=[Uicolor Randomcolor]; }//handle long Press gestures- (void) Handlelongpress: (Uilongpressgesturerecognizer *) longgesture{//when the gesture recognizer is long on time, trigger long press to change the color method if(Longgesture.state = =Uigesturerecognizerstatebegan) {LongGesture.view.backgroundColor=[Uicolor Randomcolor]; } }- (void) @end
Random Color
+ (Uicolor *) randomcolor{ return255.0255.0 the 255.0 Alpha:1];}
The accumulation of gesture recognition in iOS: Uigesturerecognizer