简单的一些手势
- (void)viewDidLoad{ [super viewDidLoad]; _imageView = [[UIImageView alloc] initWithFrame:CGRectMake(110, 160, 100, 150)]; _imageSize = CGSizeMake(100, 150); _imageView.image = [UIImage imageNamed:@"10_0.jpg"]; [self.view addSubview:_imageView]; [_imageView release]; _imageView.userInteractionEnabled = YES; //长按 UILongPressGestureRecognizer* longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPress:)]; //最短时间 //longPress.minimumPressDuration = 5.0; [_imageView addGestureRecognizer:longPress]; [longPress release]; //捏合 UIPinchGestureRecognizer* pinch = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinch:)]; [_imageView addGestureRecognizer:pinch]; [pinch release]; //移动 UIPanGestureRecognizer* pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(pan:)]; [_imageView addGestureRecognizer:pan]; [pan release]; //旋转 UIRotationGestureRecognizer* rotation = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotation:)]; [_imageView addGestureRecognizer:rotation]; [rotation release];}//旋转- (void)rotation:(UIRotationGestureRecognizer*)rotation{ _imageView.transform = CGAffineTransformMakeRotation(_rotation + rotation.rotation); //结束时,保存当前弧度 if (rotation.state == UIGestureRecognizerStateEnded) { _rotation += rotation.rotation; }}//移动- (void)pan:(UIPanGestureRecognizer*)pan{ CGPoint point = [pan translationInView:self.view]; //NSLog(@"%@",NSStringFromCGPoint(point)); _imageView.center = CGPointMake(_imageView.center.x + point.x, _imageView.center.y + point.y); // 100 10 // 110 20 120 // 130 [pan setTranslation:CGPointZero inView:self.view];}//捏合- (void)pinch:(UIPinchGestureRecognizer*)pinch{ //NSLog(@"%f",pinch.scale); /* 100*100 1.1 110*110 1.2 */ _imageView.bounds = CGRectMake(0, 0, _imageSize.width * pinch.scale, _imageSize.height * pinch.scale); //判断状态 //当状态等于结束的时候,我们需要保存当前大小作为imageView默认大小 if (pinch.state == UIGestureRecognizerStateEnded) { _imageSize = _imageView.bounds.size; }}- (void)longPress:(UILongPressGestureRecognizer*)longpress{ NSLog(@"长按");}