UIPinchGestureRecognizer 不同 x 和 y 方向的缩放视图

发布于 2024-10-22 20:13:52 字数 1061 浏览 1 评论 0原文

我不想使用比例作为经典缩放,而是想将方形的形式更改为矩形。 经过多次尝试,我的手指已经到达了矩形的角。 所以,但是如果我在内部开始一个新的捏合手势,我的视图就会变得更小,而不是像正常比例那样变大。

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 比例的方法,它不会调整大小到我的手指位置作为角。 示例

非常感谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

从来不烧饼 2024-10-29 20:13:52

解决方案

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文