How to rotate and resize the image view with single finger

后端 未结 3 1613
我寻月下人不归
我寻月下人不归 2020-12-15 02:17

I am developing an app which has feature that resizing and rotating the imageview by dragging its bottom right corner button.

I saw one app which has feature that if

3条回答
  •  渐次进展
    2020-12-15 02:22

    I had hitted the same obstacle as yours, so I developed my own modules ZDStickerView. It would be nice reference.

    First of all, be sure your view's autoresizingMask should be flexible.

        autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight
    

    otherwise resizing wouldn't work properly.

    Second, I recommends you to use "CGAffineTransformMakeRotation" and "atan2" functions to solve the rotation problem, like this:

        float ang = atan2([recognizer locationInView:self.superview].y - self.center.y,
                          [recognizer locationInView:self.superview].x - self.center.x);
        float angleDiff = deltaAngle - ang;
        self.transform = CGAffineTransformMakeRotation(-angleDiff);
    

    Third, be sure to use relative coordinate, like this:

        self.transform = CGAffineTransformMakeRotation(-angleDiff);
    

提交回复
热议问题