UIRotationGestureRecognizer *rotationRecognizer = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotate:)];
[rotationRecognizer setDelegate:self];
[self.view addGestureRecognizer:rotationRecognizer];
UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(move:)];
[panRecognizer setMinimumNumberOfTouches:1];
[panRecognizer setMaximumNumberOfTouches:1];
[panRecognizer setDelegate:self];
[self.view addGestureRecognizer:panRecognizer];
// 旋转
-(void)rotate:(id)sender {
if([(UIRotationGestureRecognizer*)sender state] == UIGestureRecognizerStateEnded) {
_lastRotation = 0.0;
return;
}
CGFloat rotation = 0.0 - (_lastRotation - [(UIRotationGestureRecognizer*)sender rotation]);
CGAffineTransform currentTransform = _imageView.transform;
CGAffineTransform newTransform = CGAffineTransformRotate(currentTransform,rotation);
[_imageView setTransform:newTransform];
_lastRotation = [(UIRotationGestureRecognizer*)sender rotation];
}
// 移动
-(void)move:(id)sender {
CGPoint translatedPoint = [(UIPanGestureRecognizer*)sender translationInView:self.view];
if([(UIPanGestureRecognizer*)sender state] == UIGestureRecognizerStateBegan) {
_startPoint = translatedPoint;
_firstX = [_imageView center].x;
_firstY = [_imageView center].y;
}
else if([(UIPanGestureRecognizer*)sender state] == UIGestureRecognizerStateChanged)
{
_changePoint = translatedPoint;
_imageView.transform = CGAffineTransformTranslate(_imageView.transform, _changePoint.x - _startPoint.x, _changePoint.y - _startPoint.y);
_startPoint = _changePoint;
}
}
- (IBAction)declineHH:(id)sender
{
CGAffineTransform aaaaaTransform = _imageView.transform;
[_imageView setTransform:CGAffineTransformIdentity];
_imageView.frame = CGRectMake(_imageView.frame.origin.x, _imageView.frame.origin.y, _imageView.frame.size.width, _imageView.frame.size.height - 2);
[_imageView setTransform:aaaaaTransform];
}
- (IBAction)declineWW:(id)sender
{
CGAffineTransform aaaaaTransform = _imageView.transform;
[_imageView setTransform:CGAffineTransformIdentity];
_imageView.frame = CGRectMake(_imageView.frame.origin.x, _imageView.frame.origin.y, _imageView.frame.size.width - 2, _imageView.frame.size.height);
[_imageView setTransform:aaaaaTransform];
}