UIPinchGestureRecognizer *pinchGestureRecognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(handlePinch:)]; [imageView addGestureRecognizer:pinchGestureRecognizer];
- (void) handlePinch:(UIPinchGestureRecognizer*) recognizer { recognizer.view.transform = CGAffineTransformScale(recognizer.view.transform, recognizer.scale, recognizer.scale); recognizer.scale = 1; }
UIPanGestureRecognizer * panRecognizer = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(handlePan:)]; //添加手勢到 tabBarController.view [tabBarController.view addGestureRecognizer:panRecognizer];
- (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]; }
/** * 處理旋轉手勢 * * @param recognizer 旋轉手勢識別器對象實例 */ - (void)handleRotation:(UIRotationGestureRecognizer *)recognizer
{ recognizer.view.transform = CGAffineTransformRotate(recognizer.view.transform, recognizer.rotation); recognizer.rotation = 0.0; }
大家需要注意的是,一個手勢只能對應一個View, 但是一個View可以有多個手勢