代码如下:
- - (void) addGestureRecognizerToView:(UIView *)view
- {
-
- UIRotationGestureRecognizer *rotationGestureRecognizer = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotateView:)];
- [view addGestureRecognizer:rotationGestureRecognizer];
-
-
- UIPinchGestureRecognizer *pinchGestureRecognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinchView:)];
- [view addGestureRecognizer:pinchGestureRecognizer];
-
-
- UIPanGestureRecognizer *panGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panView:)];
- [view addGestureRecognizer:panGestureRecognizer];
- }
-
- - (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];
- }
- }
-
- - (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;
- }
- }
-
- - (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];
- }
- }
别忘了
- [self addGestureRecognizerToView:view];
如果处理的是图片,别忘了
- [imageView setUserInteractionEnabled:YES];
- [imageView setMultipleTouchEnabled:YES];
ios开发--旋转、移动、缩放手势实例代码,布布扣,bubuko.com
ios开发--旋转、移动、缩放手势实例代码
原文:http://www.cnblogs.com/lovewx/p/3865172.html