1

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

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

任何帮助将不胜感激。

4

3 回答 3

0

找到下面的教程来缩放图像。

https://github.com/ardalahmet/SSPhotoCropperViewController

https://github.com/iosdeveloper/ImageCropper

下载

于 2013-06-10T10:28:08.070 回答
0

请尝试以下代码,您将能够旋转、缩放和移动任何对象:

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

于 2013-06-10T10:29:23.277 回答
0

-(void)oneFingerGesture:(UIPanGestureRecognizer *)recognizer { if ([recognizer state] == UIGestureRecognizerStateBegan) { //旋转 deltaAngle = atan2([recognizer locationInView:holderView.superview].y-holderView.center.y, [recognizer locationInView :holderView.superview].x-holderView.center.x); startTransform = holderView.transform; //resize 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];

}

}

于 2013-06-21T09:27:16.367 回答