See the rest: http://blog.csdn.net/totogo2010/article/details/86159401,UigesturerecognizerIntroducing gesture recognition is very important on iOS, gesture manipulation is an important feature of mobile devices, greatly increasing the ease of use of mobile devices. iOS system after 3.2, for ease of development This uses some common gestures that provide the Uigesturerecognizer class. Gesture recognition the Uigesturerecognizer class is an abstract class, and the following subclasses are specific gestures that can be developed directly using these gesture recognition.
- UITapGestureRecognizer
- Uipinchgesturerecognizer
- Uirotationgesturerecognizer
- Uiswipegesturerecognizer
- Uipangesturerecognizer
- Uilongpressgesturerecognizer
The above gestures correspond to the following actions:
- Tap (TAP)
- Pinch (two fingers inward or outward toggle, usually used in the zoom)
- Rotation (swivel)
- Swipe (sliding, fast moving)
- Pan (drag, slow move)
- Longpress (Long Press)
Uigesturerecognizer's inheritance is as follows: 2. Using gestures is a simple gesture and is divided into two steps:
- Creates a gesture instance. When creating gestures, specify a callback method that is called when the gesture starts, changes, or ends.
- Added to the view that needs to be recognized. Each gesture corresponds to only one view, and when the screen touches within the bounds of the view, if the gesture is the same as the reservation, the callback method is used.
PS: A gesture can only correspond to one view, but a view can have multiple gestures. It is recommended to run these gestures on the real machine, which is inconvenient for the simulator and may cause you to think that the gesture is invalid. 3. Pan Drag gesture:
[CPP]View Plaincopy
- Uiimageview *snakeimageview = [[Uiimageview alloc] initwithimage:[uiimage imagenamed:@"Snake.png" ]];
- Snakeimageview.frame = CGRectMake (50, 50, 100, 160);
- Uipangesturerecognizer *pangesturerecognizer = [[Uipangesturerecognizer alloc]
- Initwithtarget:self
- Action: @selector (Handlepan:)];
- [Snakeimageview Addgesturerecognizer:pangesturerecognizer];
- [Self.view Setbackgroundcolor:[uicolor Whitecolor];
- [Self.view Addsubview:snakeimageview];
Create a new ImageView, and then add a gesture callback method:
[CPP]View Plaincopy
- -(void) Handlepan: (uipangesturerecognizer*) Recognizer
- {
- Cgpoint translation = [recognizer TranslationInView:self.view];
- Recognizer.view.center = Cgpointmake (recognizer.view.center.x + translation.x,
- Recognizer.view.center.y + TRANSLATION.Y);
- [Recognizer Settranslation:cgpointzero InView:self.view];
- }