iPhone一个手指缩放手势识别器

时间:2013-06-10 09:19:48

标签: iphone uigesturerecognizer image-scaling

我想在该视图中使用一个角来处理视图的缩放和旋转。我找到了一个轮换教程。 https://github.com/kirbyt/KTOneFingerRotationGestureRecognizer

它使用atan2f函数自定义UIGesturRecognizer进行旋转。 但是我没有找到任何可扩展的东西。任何人都可以告诉我哪个类似的数学函数用于缩放或任何教程帮助用于此目的。

任何帮助将不胜感激。

3 个答案:

答案 0 :(得分:0)

答案 1 :(得分:0)

请尝试使用此代码,您可以旋转,缩放和移动任何对象:

https://github.com/erica/iphone-3.0-cookbook-/tree/master/C08-Gestures/14-Resize%20And%20Rotate/

答案 2 :(得分:0)

- (void)oneFingerGesture:(UIPanGestureRecognizer *)识别器 {     if([识别器状态] == UIGestureRecognizerStateBegan)     {         //回转         deltaAngle = atan2([recognizer locationInView:holderView.superview] .y-holderView.center.y,[recognizer locationInView:holderView.superview] .x-holderView.center.x);         startTransform = holderView.transform;         //调整         prevPoint = [识别器locationInView:holderView.superview];         [holderView setNeedsDisplay];

}
else if ([recognizer state] == UIGestureRecognizerStateChanged)
{
    //rotation
    float ang = atan2([recognizer locationInView:holderView.superview].y - holderView.center.y, [recognizer locationInView:holderView.superview].x - holderView.center.x);
    float angleDiff = deltaAngle - ang;
    holderView.transform = CGAffineTransformRotate(startTransform, -angleDiff);

    //resize
    CGPoint point = [recognizer locationInView:holderView.superview];
    float wChange = 0.0, hChange = 0.0, value=0.0;

    wChange = (point.x - prevPoint.x);
    hChange = (point.y - prevPoint.y);

    CGFloat radians = atan2f(holderView.transform.b, holderView.transform.a);
    CGFloat degrees = radians * (180 / M_PI);

    if (degrees<=0 && degrees>=-90) {
        value=wChange;
    }
    else if (degrees<=-90 && degrees>=-180){
        value=-hChange;
    }
    else if (degrees<=180 && degrees>=90){
        value=-wChange;
    }
    else if (degrees<=90 && degrees>=0){
        value=hChange;
    }

    holderView.bounds = CGRectMake(holderView.bounds.origin.x, holderView.bounds.origin.y, holderView.bounds.size.width + (value), holderView.bounds.size.height + (value));
    imageview.frame = CGRectMake(12, 12, holderView.bounds.size.width-24, holderView.bounds.size.height-27);
    View_marqueRotate.frame =CGRectMake(holderView.bounds.size.width-25, holderView.bounds.size.height-25, 25, 25);
    View_marqueClose.frame = CGRectMake(0, 0, 25, 25);

    prevPoint = [recognizer locationInView:holderView.superview];
    [holderView setNeedsDisplay];


}
else if ([recognizer state] == UIGestureRecognizerStateEnded)
{
    //rotation
    deltaAngle = atan2([recognizer locationInView:holderView.superview].y-holderView.center.y, [recognizer locationInView:holderView.superview].x-holderView.center.x);
    startTransform = holderView.transform;

    //resize
    prevPoint = [recognizer locationInView:holderView.superview];
    [holderView setNeedsDisplay];

}

}