UIPinchGestureRecognizer Scale view in different x and y directions

爷,独闯天下 提交于 2019-12-04 11:37:27

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!