在ScrollView中旋转缩放ImageView?

我有一个UIScrollView有一个缩放UIImageView ,即它实现:

 - (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView { return self.imageView; } 

我想添加一个UIRotationGestureRecognizer这个UIRotationGestureRecognizer ,我这样做,如下所示:

 _rotationGestureRecognizer = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotate:)]; [self.imageView addGestureRecognizer:_rotationGestureRecognizer]; -(void)rotate:(id)sender { UIRotationGestureRecognizer *rotationGestureRecognizer = [(UIRotationGestureRecognizer*)sender retain]; if(rotationGestureRecognizer.state == UIGestureRecognizerStateEnded) { self.lastRotation = 0.0; return; } CGFloat rotation = 0.0 - (self.lastRotation - rotationGestureRecognizer.rotation); rotationGestureRecognizer.view.transform = CGAffineTransformRotate(rotationGestureRecognizer.view.transform, rotation); self.lastRotation = rotationGestureRecognizer.rotation; [rotationGestureRecognizer release]; } 

我只是想知道,甚至可以做到这一点? 看来UIScrollView阻止了我的UIImageView触摸,因为什么都没有发生。 Applebuild议不要在UIScrollView使用缩放视图来执行此操作吗?

下面的代码工作。添加手势scrollView而不是imageView。

  UIRotationGestureRecognizer* _rotationGestureRecognizer = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotate:)]; [self.scrollView addGestureRecognizer:_rotationGestureRecognizer]; 
 -(void)rotate:(UIRotationGestureRecognizer *)sender { [self bringSubviewToFront:[(UIRotationGestureRecognizer*)sender view]]; if([(UIRotationGestureRecognizer*)sender state] == UIGestureRecognizerStateEnded) { lastRotation = 0.0; return; } CGFloat rotation = 0.0 - (lastRotation - [(UIRotationGestureRecognizer*)sender rotation]); CGAffineTransform currentTransform = [(UIPinchGestureRecognizer*)sender view].transform; CGAffineTransform newTransform = CGAffineTransformRotate(currentTransform, rotation); [[(UIRotationGestureRecognizer*)sender view] setTransform:newTransform]; lastRotation = [(UIRotationGestureRecognizer*)sender rotation]; lastRotation = [(UIRotationGestureRecognizer*)sender rotation]; }