UIPinchGestureRecognizer缩放视图在不同的x和y方向 [英] UIPinchGestureRecognizer Scale view in different x and y directions

查看:121
本文介绍了UIPinchGestureRecognizer缩放视图在不同的x和y方向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不想将比例用作经典缩放,例如,我想将方形的形式更改为矩形. 经过大量尝试后,我的手指已经伸到矩形的角上了. 因此,但是,如果我在内部开始一个新的捏手势,则视图的手指会变小,而不是像正常比例尺那样变大.

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];
}

有谁知道一种制作X-Y-Scale的方法,该方法不会调整到我的手指角位置.

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

非常感谢

推荐答案

解决方案

- (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];
}
}  

在xDif和yDif中添加了我与视图侧面之间的触摸距离.
缩放后,我将它们添加到大小

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

这篇关于UIPinchGestureRecognizer缩放视图在不同的x和y方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆