Add all the gestures
- -(void) Addgesturerecognizertoview: (UIView *) View
- {
- //Rotation gestures
- Uirotationgesturerecognizer *rotationgesturerecognizer = [[Uirotationgesturerecognizer alloc] InitWithTarget:self Action: @selector (Rotateview:)];
- [View Addgesturerecognizer:rotationgesturerecognizer];
- //Zoom gesture
- Uipinchgesturerecognizer *pinchgesturerecognizer = [[Uipinchgesturerecognizer alloc] initwithtarget:self action:@ Selector (Pinchview:)];
- [View Addgesturerecognizer:pinchgesturerecognizer];
- //Mobile gestures
- Uipangesturerecognizer *pangesturerecognizer = [[Uipangesturerecognizer alloc] initwithtarget:self action: @selector ( Panview:)];
- [View Addgesturerecognizer:pangesturerecognizer];
- }
- Handling Rotation gestures
- -(void) Rotateview: (Uirotationgesturerecognizer *) Rotationgesturerecognizer
- {
- UIView *view = Rotationgesturerecognizer.view;
- if (rotationgesturerecognizer.state = = Uigesturerecognizerstatebegan | | rotationgesturerecognizer.state = = uigesturerecognizerstatechanged) {
- View.transform = Cgaffinetransformrotate (View.transform, rotationgesturerecognizer.rotation);
- [Rotationgesturerecognizer setrotation:0];
- }
- }
- Handling Zoom gestures
- -(void) Pinchview: (Uipinchgesturerecognizer *) Pinchgesturerecognizer
- {
- UIView *view = Pinchgesturerecognizer.view;
- if (pinchgesturerecognizer.state = = Uigesturerecognizerstatebegan | | pinchgesturerecognizer.state = = uigesturerecognizerstatechanged) {
- View.transform = Cgaffinetransformscale (View.transform, Pinchgesturerecognizer.scale, PinchGestureRecognizer.scale );
- Pinchgesturerecognizer.scale = 1;
- }
- }
- Handling Drag gestures
- -(void) Panview: (Uipangesturerecognizer *) Pangesturerecognizer
- {
- UIView *view = Pangesturerecognizer.view;
- if (pangesturerecognizer.state = = Uigesturerecognizerstatebegan | | pangesturerecognizer.state = = uigesturerecognizerstatechanged) {
- Cgpoint translation = [Pangesturerecognizer TranslationInView:view.superview];
- [View SetCenter: (Cgpoint) {view.center.x + translation.x, View.center.y + translation.y}];
- [Pangesturerecognizer Settranslation:cgpointzero InView:view.superview];
- }
- }
Don't forget
Java code
- [Self addgesturerecognizertoview:view];
If you're dealing with a picture, don't forget.
C code
- [ImageView Setuserinteractionenabled:yes];
- [ImageView Setmultipletouchenabled:yes];
iOS development--rotate, move, and scale gesture instance code