Uigesturerecognizer subclasses have a lot of gestures, through the use of the gesture can be used to perform different operations, the following to describe their basic usage of all gesture configuration is basically the same, just for different gestures inside some properties can be set, Like tap to go in there. There are two parameters that can be set by the number of clicks, and the click-to-hand index. If you do not know this gesture can be configured to specify the parameters, then click into the corresponding. h file view
UITapGestureRecognizer *tapgesture = [[UITapGestureRecognizer alloc]initwithtarget:self Action: @selector ( Processgesturerecongnizer:)];//click Gestures [tapgesture setnumberoftouchesrequired:1]; [Tapgesture setnumberoftapsrequired:1]; [_view addgesturerecognizer:tapgesture]; [Tapgesture release];
-(void) Processgesturerecongnizer: (Uigesturerecognizer *) gesture{ if ([Gesture iskindofclass:[ UITapGestureRecognizer class]]) { [self positionanimation];} }
#pragma mark-inituserinterface-(void) inituserinterface{_view = [[UIView alloc]init]; [_view setbounds:cgrectmake (0, 0, 200, 200)]; [_view Setcenter:cgpointmake (Cgrectgetmidx (self.view.bounds), Cgrectgetmidy (Self.view.bounds))]; [_view Setbackgroundcolor:[uicolor Graycolor]; [Self.view Addsubview:_view]; Two finger toggle gestures uipinchgesturerecognizer *pinch = [[Uipinchgesturerecognizer alloc]initwithtarget:self Action: @selector ( Processgesturerecognizer:)]; [Pinch setdelegate:self];//set agent [_view Addgesturerecognizer:pinch]; Add this gesture to view [pinch release]; Rotation gesture Uirotationgesturerecognizer *rotation = [[Uirotationgesturerecognizer alloc]initwithtarget:self action:@ Selector (processgesturerecognizer:)]; [Rotation setdelegate:self]; [_view addgesturerecognizer:rotation]; [Rotation release]; Long-Press gesture uilongpressgesturerecognizer *longpress = [[Uilongpressgesturerecognizer alloc]initwithtarget:self action:@ Selector (processgesturerecognizer:)]; LongPress.minimumpressduration = 2; [_view addgesturerecognizer:longpress]; [Longpress release]; Swipe gesture--left
Uiswipegesturerecognizer *leftswipe = [[Uiswipegesturerecognizer alloc]initwithtarget:self Action: @selector ( Processgesturerecognizer:)]; [Leftswipe setdirection:uiswipegesturerecognizerdirectionleft];//configuration slide direction [Self.view addgesturerecognizer:leftswipe ]; [Leftswipe release]; Swipe gesture--right uiswipegesturerecognizer *rightswipe = [[Uiswipegesturerecognizer alloc]initwithtarget:self action:@ Selector (processgesturerecognizer:)]; [Rightswipe Setdirection:uiswipegesturerecognizerdirectionright]; [Self.view Addgesturerecognizer:rightswipe]; [Rightswipe release]; Drag gesture Uipangesturerecognizer *pan = [[Uipangesturerecognizer alloc]initwithtarget:self Action: @selector ( Processgesturerecognizer:)]; [Pan setdelegate:self]; [_view Addgesturerecognizer:pan]; [Pan release]; } #pragma mark--Gesturerrecognizer methods//Proxy Method-(BOOL) Gesturerecognizer: (Uigesturerecognizer *) Gesturerecognizer Shouldberequiredtofailbygesturerecognizer: (Uigesturerecognizer *) Othergesturerecognizer{return NO;} Gesture action allows the corresponding gesture to be performed accordingly-(void) Processgesturerecognizer: (Uigesturerecognizer *) gesture{//Judging gesture type if ([Gesture Iski Ndofclass:[uipinchgesturerecognizer class]] {Uipinchgesturerecognizer *pinch = (Uipinchgesturerecognizer *) ges Ture Static float lastscale;//variable record last size if (pinch.state = = Uigesturerecognizerstatebegan) {Lastscale = Pinc h.scale;//gesture starts assigning the initial scale to a static variable for easy updating}else if (pinch.state = = uigesturerecognizerstatechanged) {[_view sett Ransform:cgaffinetransformscale (_view.transform, 1+ (Pinch.scale-lastscale), 1+ (Pinch.scale-lastscale))];// Let view dynamically zoom in or out Lastscale = pinch.scale;//Update the value of the scale-(this allows the view to remain in a changed state instead of the initial state)//This method does not need to be updated lastscal The value of E is all starting from the prototype//[_view Settransform:cgaffinetransformmakescale (1+ (Pinch.scale-lastscale), 1+ (Pinch.scale-las TScale)]; }}else if ([Gesture Iskindofclass:[uirotationgesturerecognizer class]]) {UirotationgeSturerecognizer *rotation = (Uirotationgesturerecognizer *) gesture; static float lastrotation; if (rotation.state = = Uigesturerecognizerstatebegan) {lastrotation = rotation.rotation; }else if (rotation.state = = uigesturerecognizerstatechanged) {[_view settransform:cgaffinetransformrotate (_view . Transform, Rotation.rotation-lastrotation)]; Lastrotation = rotation.rotation; }} else if ([Gesture Iskindofclass:[uilongpressgesturerecognizer class]]) {Uilongpressgesturerecognizer *longpress = (Uilongpressgesturerecognizer *) gesture; if (longpress.state = = Uigesturerecognizerstatebegan) {Uialertview *alert = [[Uialertview alloc]initwithtitle: @ "warm hint" message:@ "Long press Begin" delegate:self cancelbuttontitle:@ "OK" otherbuttontitles:nil]; [Alert show]; [Alert release]; }} else if ([Gesture Iskindofclass:[uiswipegesturerecognizer class]]) {UiswipegeSturerecognizer *swipe = (Uiswipegesturerecognizer *) gesture; if (swipe.direction = = uiswipegesturerecognizerdirectionleft) {[UIView animatewithduration:1 animations:^{ [_view Setcenter:cgpointmake (Cgrectgetminx (self.view.bounds), Cgrectgetmidy (Self.view.bounds))]; }]; }else{[UIView animatewithduration:1 animations:^{[_view setcenter:cgpointmake (Cgrectgetmaxx (SE Lf.view.bounds), Cgrectgetmidy (Self.view.bounds))]; }]; }} else if ([Gesture Iskindofclass:[uipangesturerecognizer class]]) {Uipangesturerecognizer *pan = (Uipangesturerecognizer *) gesture; Static Cgpoint lastlocation; if (pan.state = = Uigesturerecognizerstatebegan) {lastlocation = _view.center; }else if (pan.state = = uigesturerecognizerstatechanged) {Cgpoint translationpoint = [Pan TRANSLATIONINV Iew:self.view]; _view.center = Cgpointmake (translAtionpoint.x + lastlocation.x, translationpoint.y+ lastlocation.y); }else if (pan.state = = uigesturerecognizerstateended) {lastlocation = Cgpointzero; } }}
iOS Uigesturerecognizer gesture Basics using parsing