gpt4 book ai didi

iphone - UIPinchGestureRecognizer 在不同的 x 和 y 方向缩放 View

转载 作者:搜寻专家 更新时间:2023-10-30 19:52:57 24 4
gpt4 key购买 nike

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

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

非常感谢

最佳答案

得到解决方案

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

关于iphone - UIPinchGestureRecognizer 在不同的 x 和 y 方向缩放 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5349907/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com