有什么办法可以告诉我屏幕有多难按下 [英] Is there any way at all that I can tell how hard the screen is being pressed

查看:205
本文介绍了有什么办法可以告诉我屏幕有多难按下的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想找到触摸的压力。我只是不知道如何通过越狱和获取原始触摸数据来实现这一结果。有谁知道我会怎么做?

I want to find the pressure of the touch. I just don't know how to accomplish that result with out jailbreaking it and getting the raw touch data. Does anyone know How I would do this?

推荐答案

你无法从SDK 获得压力无证方法。但是可以检测未记录方法的触摸大小。

You cannot get the pressure from the SDK nor undocumented methods. However you can detect the size of touch with undocumented methods.

在GSEvent中,是UIEvent的低级表示,有一种结构称为 GSPathInfo

In the GSEvent, which is a lower-level representation of UIEvent, there is a structure known as GSPathInfo with members:

typedef struct GSPathInfo {
    unsigned char pathIndex;        // 0x0 = 0x5C
    unsigned char pathIdentity;     // 0x1 = 0x5D
    unsigned char pathProximity;    // 0x2 = 0x5E
    CGFloat pathPressure;               // 0x4 = 0x60
    CGFloat pathMajorRadius;        // 0x8 = 0x64
    CGPoint pathLocation;           // 0xC = 0x68
    GSWindowRef pathWindow;         // 0x14 = 0x70
} GSPathInfo;

我们注意到 pathPressure pathMajorRadius 。我可以向你保证压力成员没用 - 它总是给出0.然而 pathMajorRadius 确实包含有意义的信息 - 它给出了触摸的主要半径以毫米为单位。因此,如果是半径较重或轻触,您可以给出非常粗略的估计。

We notice that there is a pathPressure and pathMajorRadius. I can assure you the pressure member is useless – it always gives 0. However pathMajorRadius does contain meaningful information – it gives the major radius of the touch in millimeters. You can therefore give an extremely rough estimation if it's a heavy touch or light touch from the radius.

  -(void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event {
     GSEventRef gsevent = [event _gsEvent];
     GSPathInfo first_touch = GSEventGetPathInfoAtIndex(gsevent, 0);
     if (first_touch.pathMajorRadius >= 9)
        NSLog(@"huge (heavy) touch");
     else
        NSLog(@"little (light) touch");
  }

让我再次警告你这是无证件和你不应该在AppStore应用程序中使用它。

Let me warn you again this is undocumented and you should not use it in AppStore apps.

编辑:在3.2及以上的GSPathInfo的 pathMajorRadius 在UITouch中也可以作为未记录的属性使用:

On 3.2 and above the pathMajorRadius of a GSPathInfo is also available as an undocumented property in UITouch:

@property(assign, nonatomic, setter=_setPathMajorRadius:) CGFloat _pathMajorRadius;

所以上面的代码可以使用纯Objective-C重写:

so the code above could be rewritten using pure Objective-C:

  -(void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event {
     UITouch* any_touch = [touches anyObject];
     if (any_touch._pathMajorRadius >= 9)
        NSLog(@"huge (heavy) touch");
     else
        NSLog(@"little (light) touch");
  }

这篇关于有什么办法可以告诉我屏幕有多难按下的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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