0

我有一个非常奇怪的问题,我正在我的应用程序中实现 UIRotationGestureRecognizer 来旋转图像。我的问题是,有时当您开始旋转图像时,它会跳到另一根手指。示例:我用一根手指拖动图像,然后用第二根手指开始旋转,但图像转到第二根手指。这正常吗?可以修复吗?我正在使用的代码是:

if([recognizer state] == UIGestureRecognizerStateEnded) {

    prevRotation = 0.0;
    return;
}

CGFloat newRotation = 0.0 - (prevRotation - [recognizer rotation]);

CGAffineTransform currentTransformation = image.transform;
CGAffineTransform newTransform = CGAffineTransformRotate(currentTransformation, newRotation);

image.transform = newTransform;

prevRotation = [recognizer rotation];

我尝试保存中心的最后一个位置并再次应用它,但它也不起作用,如下所示:

lastPoint=image.center;

if([recognizer state] == UIGestureRecognizerStateEnded) {

    prevRotation = 0.0;
    return;
}

CGFloat newRotation = 0.0 - (prevRotation - [recognizer rotation]);

CGAffineTransform currentTransformation = image.transform;
CGAffineTransform newTransform = CGAffineTransformRotate(currentTransformation, newRotation);

image.transform = newTransform;

prevRotation = [recognizer rotation];
image.center=lastPoint;
4

1 回答 1

0

试试这个代码:

-(void)rotate:(id)sender
{

    [self.view bringSubviewToFront:[(UIRotationGestureRecognizer*)sender view]];

    self.imageTag = [[sender view]tag];
    NSLog(@"sender tag %d", self.imageTag);
    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];
}
于 2012-07-23T06:59:08.613 回答