UIPanGestureRecognizer实现缩放和旋转UIView

时间:2015-04-28 10:10:03

标签: ios objective-c rotation uipangesturerecognizer

有一个UIView A.我在视图A上放了一个图标并尝试使用平移手势来缩放和旋转此视图A.缩放功能工作正常,但我无法进行旋转工作。代码如下。任何帮助将不胜感激。感谢

- (void)scaleAndRotateWatermark:(UIPanGestureRecognizer *)gesture
{
    if (gesture.state == UIGestureRecognizerStateChanged
        || gesture.state == UIGestureRecognizerStateEnded) 
    {

        UIView *child = gesture.view;
        UIView *view = child.superview;

        CGPoint translatedPoint = [gesture translationInView:view];

    CGPoint originCenter = child.center;
    CGPoint newCenter = CGPointMake(child.centerX+translatedPoint.x, child.centerY+translatedPoint.y);

    float origX = originCenter.x;
    float origY = originCenter.y;
    float newX = newCenter.x;
    float newY = newCenter.y;

    float originDis = (origX*origX) + (origY*origY);
    float newDis = (newX*newX) + (newY*newY);

    float scale = newDis/originDis;

    view.transform = CGAffineTransformScale(view.transform, scale, scale);
    // rotation calulate here 

    // need your help

    // end of rotation

    [guesture setTranslation:CGPointZero inView:_videoPreviewLayer];
    }
}

0 个答案:

没有答案