How to rotate and resize an image with one finger

I am developing an application that has a function that resizes and rotates an image by dragging its button in the lower right corner.

I saw one application that has a function that, if we drag the button of the lower right corner diagonally, reduce the size of the image, or if we drag the button left or right, the image was viewed in the direction. I want to implement this function in my application

I'm struggling to implement a single rotation of the finger, as well as resize the image.

I could successfully resize the image by dragging its button on the lower right corner. But I don’t have enough knowledge to add a twist to the image view.

Please guide me correctly.

I added the code below to resize the image by dragging its right corner.

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *touch = [[event allTouches] anyObject];

    touchStart = [[touches anyObject] locationInView:imageView];
    isResizingLR = (containerVw.bounds.size.width - touchStart.x < kResizeThumbSize && containerVw.bounds.size.height - touchStart.y < kResizeThumbSize);

}



- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
CGPoint touchPoint = [[touches anyObject] locationInView:imageView];
CGPoint previous=[[touches anyObject]previousLocationInView:imageView];

UITouch *touch = [[event allTouches] anyObject];


float  deltaWidth = touchPoint.x-previous.x;
float  deltaHeight = touchPoint.y-previous.y;


    if (isResizingLR) {
        containerVw.frame = CGRectMake(containerVw.frame.origin.x, containerVw.frame.origin.y,touchPoint.x + deltaWidth, touchPoint.y + deltaWidth); 
        imageView.frame = CGRectMake(imageView.frame.origin.x, imageView.frame.origin.y,touchPoint.x + deltaWidth, touchPoint.y + deltaWidth);                      
        dragIm.frame = CGRectMake(containerVw.frame.size.width-10, containerVw.frame.size.height-10,20,20);


    if (!isResizingLR) {
        containerVw.center = CGPointMake(containerVw.center.x + touchPoint.x touchStart.x,containerVw.center.y + touchPoint.y - touchStart.y);
    }
}

enter image description here

+4
source share
3 answers

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

First of all, make sure your autoresizingMask method needs to be flexible.

    autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight

otherwise, resizing will not work properly.

Secondly, I recommend using the "CGAffineTransformMakeRotation" and "atan2" functions to solve the rotation problem, for example:

    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 a relative coordinate, for example:

    self.transform = CGAffineTransformMakeRotation(-angleDiff);
+10

, https://github.com/zedoul/ZDStickerView.

IQStickerView OneFingerRotation, Scale, Resize Close.

:

  • .
  • Finger.
  • / , , .
  • IQStickerView.
  • UIScrollView.
  • Fast responsiveness.
0
source

All Articles