5

i don't want to use the scale as classic zoom, instead i want to change the form of quadrates to a rectangle for example. After a lot of trying i'm that far that my fingers are the corners of the rectangle. So but if i start a new pinch gesture inside my view gets smaller to my fingers instead of getting bigger like the normal scale does.

if ([gestureRecognizer numberOfTouches] >1) {
    //getting width and height between gestureCenter and one of my finger
    float x = [gestureRecognizer locationInView:self].x - [gestureRecognizer locationOfTouch:0 inView:self].x;
    if (x<0) {
        x *= -1;
    }
    float y = [gestureRecognizer locationInView:self].y - [gestureRecognizer locationOfTouch:0 inView:self].y;
    if (y<0) {
        y *= -1;
    }
    //double size cause x and y is just the way from the middle to my finger
    float width = x*2;
    if (width < 1) {
        width = 1;
    }
    float height = y*2;
    if (height < 1) {
        height = 1;
    }
    self.bounds = CGRectMake(self.bounds.origin.x , self.bounds.origin.y , width, height);
    [gestureRecognizer setScale:1];
    [[self layer] setBorderWidth:2.f];
}

does anyone know a way to make a X-Y-Scale which don't resize to my fingers position as corners. Example

Thank you very much

Seega
  • 3,001
  • 2
  • 34
  • 48
  • Possible duplicate of [Scale of UIPinchGestureRecognizer in horizontal and vertical directions separately](https://stackoverflow.com/questions/12354959/scale-of-uipinchgesturerecognizer-in-horizontal-and-vertical-directions-separate) – Fattie Jul 12 '17 at 00:52
  • Why should this question be a duplicate if it is older and even has an accepted answer? – Seega Jul 12 '17 at 15:03

1 Answers1

12

Got the solution

- (void) scaleSelfWith:(UIPinchGestureRecognizer *)gestureRecognizer{
if ([gestureRecognizer numberOfTouches] >1) {

    //getting width and height between gestureCenter and one of my finger
    float x = [gestureRecognizer locationInView:self].x - [gestureRecognizer locationOfTouch:1 inView:self].x;
    if (x<0) {
        x *= -1;
    }
    float y = [gestureRecognizer locationInView:self].y - [gestureRecognizer locationOfTouch:1 inView:self].y;
    if (y<0) {
        y *= -1;
    }

    //set Border
    if (gestureRecognizer.state == UIGestureRecognizerStateBegan) {
        xDis = self.bounds.size.width - x*2;
        yDis = self.bounds.size.height - y*2;
    }

    //double size cause x and y is just the way from the middle to my finger
    float width = x*2+xDis;
    if (width < 1) {
        width = 1;
    }
    float height = y*2+yDis;
    if (height < 1) {
        height = 1;
    }
    self.bounds = CGRectMake(self.bounds.origin.x , self.bounds.origin.y , width, height);
    [gestureRecognizer setScale:1];
    [[self layer] setBorderWidth:2.f];
}
}  

added xDif and yDif with the distance of my touch from the side of the view.
after scale i add them to the size

Seega
  • 3,001
  • 2
  • 34
  • 48
  • Great! Other solutions I found use CGAffineTransformScale so it scales whole view & its subview. – nahung89 Sep 18 '14 at 00:32
  • It might be that in the meanwhile there are easier solutions. The code is quite old and objective-c made a big evolution. – Seega Sep 25 '14 at 09:26