如何检测手势中的捏和捏?

时间:2022-09-06 21:09:30

Instead of scaling, which I think pinch gesture is usually used for, I am looking to just detect whether the pinch was a pinch in vs pinch out so I can collapse or expand some table sections. How would I go about doing that?

而不是缩放,我认为缩放手势通常是用来做的,我只是想检测一下缩放手势是否缩放了,这样我就可以折叠或者展开一些表格了。我该怎么做呢?

3 个解决方案

#1


7  

Well, that seems an easy one. The UIPinchGestureRecognizer class has only two properties, scale and velocity. It seems logical that a negative scale would mean an inward pinch, a positive scale an outward pinch.

这看起来很简单。uipinchsturerecognizer类只有两个性质,尺度和速度。从逻辑上看,负刻度意味着向内的缩放,正刻度意味着向外的缩放。

NB: "negative" might be misleading. "Smaller" is 0.0 < scale < 1.0, "bigger" is scale > 1.0.

注:“负面”可能具有误导性。“小”为0.0 < scale < 1.0,“大”为scale > 1.0。

#2


10  

The "scale" property is less than 1 for pinch-in gesture and greater than 1 for pinch-out. This happens for all pinches with 2 fingers.

“比例”属性小于1的手势,大于1的手势。这发生在所有有两个手指的捏。

What I also observed was that if I pinched in with 5 fingers (which is the shortcut to minimize-to-home), the scale value comes exactly 1.0 - everytime. But this is not supported by any Apple documentation that I'm aware of.

我还观察到,如果我用5个手指夹住(这是最小化到home的捷径),刻度值每次精确到1.0。但我所知道的任何苹果文档都不支持这一点。

You can experiment what the values are coming by simply putting an NSLog in your pinch handling selector

您可以通过在pinch处理选择器中放置一个NSLog来试验这些值。

NSLog(@"Scale: %.2f | Velocity: %.2f",pinch.scale,pinch.velocity);

#3


2  

You were right to look at the scale property however it switches around 1, not zero.

你看比例性质是对的但是它在1附近转,而不是0。

    - (BOOL) pinchWasOutwards:(UIGestureRecognizer *)gestureRecognizer
    {
        return gestureRecognizer.scale > 1;
    }

#1


7  

Well, that seems an easy one. The UIPinchGestureRecognizer class has only two properties, scale and velocity. It seems logical that a negative scale would mean an inward pinch, a positive scale an outward pinch.

这看起来很简单。uipinchsturerecognizer类只有两个性质,尺度和速度。从逻辑上看,负刻度意味着向内的缩放,正刻度意味着向外的缩放。

NB: "negative" might be misleading. "Smaller" is 0.0 < scale < 1.0, "bigger" is scale > 1.0.

注:“负面”可能具有误导性。“小”为0.0 < scale < 1.0,“大”为scale > 1.0。

#2


10  

The "scale" property is less than 1 for pinch-in gesture and greater than 1 for pinch-out. This happens for all pinches with 2 fingers.

“比例”属性小于1的手势,大于1的手势。这发生在所有有两个手指的捏。

What I also observed was that if I pinched in with 5 fingers (which is the shortcut to minimize-to-home), the scale value comes exactly 1.0 - everytime. But this is not supported by any Apple documentation that I'm aware of.

我还观察到,如果我用5个手指夹住(这是最小化到home的捷径),刻度值每次精确到1.0。但我所知道的任何苹果文档都不支持这一点。

You can experiment what the values are coming by simply putting an NSLog in your pinch handling selector

您可以通过在pinch处理选择器中放置一个NSLog来试验这些值。

NSLog(@"Scale: %.2f | Velocity: %.2f",pinch.scale,pinch.velocity);

#3


2  

You were right to look at the scale property however it switches around 1, not zero.

你看比例性质是对的但是它在1附近转,而不是0。

    - (BOOL) pinchWasOutwards:(UIGestureRecognizer *)gestureRecognizer
    {
        return gestureRecognizer.scale > 1;
    }