First, Uigesturerecognizer introduction gestures are often used in iOS, can be said to be very important to exist, before, most of them are through the touch method to determine the gesture, But after iOS system 3.2, Uigesturerecongnizer abstract classes were added and several subclasses were abstracted
- UITapGestureRecognizer (Point)
- Uipinchgesturerecognizer (zoom)
- Uirotationgesturerecognizer (swivel)
- Uiswipegesturerecognizer (Swipe)
- Uipangesturerecognizer (drag)
- Uilongpressgesturerecognizer (Long Press)
These gestures are very simple, basically understand one of the usage, the other will all understand, so we today take the drag as an example, to do a side-by-side expand the menu bar we first to understand the basic usage of these gestures 1, zoom gesture
Uipinchgesturerecognizer *pinchgesturerecognizer = [[Uipinchgesturerecognizer alloc] initwithtarget:self Action: @selector (handlepinch:)]; [ImageView Addgesturerecognizer:pinchgesturerecognizer];
callback method
-(void) Handlepinch: (uipinchgesturerecognizer*) recognizer { = Cgaffinetransformscale (Recognizer.view.transform, Recognizer.scale, Recognizer.scale); 1 ; }
2. Drag gestures
Uipangesturerecognizer * Panrecognizer = [[Uipangesturerecognizer alloc]initwithtarget:self Action: @selector ( Handlepan:)]; // add gestures to Tabbarcontroller.view [Tabbarcontroller.view Addgesturerecognizer:panrecognizer];
callback method
-(void) Handlepan: (uipangesturerecognizer*) recognizer { = [recognizer TranslationInView:self.view]; = Cgpointmake (recognizer.view.center.x ++ translation.y); [Recognizer Settranslation:cgpointzero InView:self.view]; }
3. Rotating gestures
/* * * handle rotation gesture * * @param recognizer Rotation gesture Recognizer Object Instance * /-(void) Handlerotation: (Uirotationgesturerecognizer *
{ = cgaffinetransformrotate (recognizer.view.transform, recognizer.rotation); 0.0 ; }
It is important to note that a gesture can only correspond to one view, but a view can have multiple gestures
Basic gesture Recognition