5

我不想将比例用作经典缩放,而是想将四边形的形式更改为矩形。经过大量尝试后,我的手指已经是矩形的角了。所以,但是如果我在我的视图中开始一个新的捏合手势,我的手指会变小,而不是像正常比例那样变大。

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

有谁知道制作 XY 比例尺的方法,它不会将我的手指位置调整为角落。 例子

非常感谢

4

1 回答 1

12

得到了解决方案

- (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 以及我触摸到视图侧面的距离。
缩放后我将它们添加到大小

于 2011-03-18T13:57:26.123 回答