如何在iOS SDK中使用两个fingure touch旋转UIImageView ..我知道这很简单,但因为我是这个技术的新手,所以无法理解......
如何使用UIRotationGestureRecognizer来实现这个......
请帮我解决这个问题...
感谢。
答案 0 :(得分:12)
在视图上执行加载或imageview创建函数的代码:m_ctrlImgVwShowImage - 你的imageview
UIRotationGestureRecognizer *rotationRecognizer = [[[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotate:)] autorelease];
[rotationRecognizer setDelegate:self];
[m_ctrlImgVwShowImage addGestureRecognizer:rotationRecognizer];
//lastRotation is a cgfloat member variable
-(void)rotate:(id)sender {
if([(UIRotationGestureRecognizer*)sender state] == UIGestureRecognizerStateEnded) {
_lastRotation = 0.0;
return;
}
CGFloat rotation = 0.0 - (_lastRotation - [(UIRotationGestureRecognizer*)sender rotation]);
CGAffineTransform currentTransform = m_ctrlImgVwShowImage.transform;
CGAffineTransform newTransform = CGAffineTransformRotate(currentTransform,rotation);
[m_ctrlImgVwShowImage setTransform:newTransform];
_lastRotation = [(UIRotationGestureRecognizer*)sender rotation];
}