有什么方法可以让我知道按屏幕的力度有多大

发布于 2024-08-18 08:45:03 字数 58 浏览 9 评论 0原文

我想找到触摸的压力。我只是不知道如何在不越狱并获取原始触摸数据的情况下实现该结果。有谁知道我会怎么做?

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?

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

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

发布评论

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

评论(4

别闹i 2024-08-25 08:45:03

您无法从 SDK 或未记录的方法中获得压力。但是,您可以使用未记录的方法检测触摸的大小。


在 GSEvent(UIEvent 的较低级别表示)中,有一个名为 GSPathInfo 与成员:

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;

我们注意到有一个 pathPressurepathMajorRadius。我可以向您保证压力构件是无用的 - 它总是给出 0。但是 pathMajorRadius 确实包含有意义的信息 - 它给出了触摸的主半径(以毫米为单位)。因此,您可以对半径上是重接触还是轻接触给出极其粗略的估计。

  -(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 应用程序中使用它。


编辑:在 3.2 及更高版本中,GSPathInfo 的 pathMajorRadius 也可以作为 UITouch 中的未记录属性:

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

因此可以使用纯 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");
  }

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


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;

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");
  }

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


Edit: 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;

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");
  }
滴情不沾 2024-08-25 08:45:03

从 iOS 8.0 开始,UITouch 有一个公共 majorRadius 属性,可以告诉您触摸的大致大小。

As of iOS 8.0, UITouch has a public majorRadius property which tells you the approximate size of the touch.

流殇 2024-08-25 08:45:03

在 iOS 3.2 和 4.0 中,您可以像这样更直接地获取值:

UITouch* touch = ...// get the touch object
float radius = [[touch valueForKey:@"pathMajorRadius"] floatValue];

仍然没有 App Store 批准,但对于自定义内容很方便。

In iOS 3.2 and 4.0 you can get the value more directly like this:

UITouch* touch = ...// get the touch object
float radius = [[touch valueForKey:@"pathMajorRadius"] floatValue];

Still not App Store approved, but handy for custom stuff.

£冰雨忧蓝° 2024-08-25 08:45:03

使用 SDK 是不可能的。无论如何,它不会公开该数据。而且屏幕无法感知压力,甚至是否向操作系统报告触摸“大小”也不得而知。遗憾的是,您想要做的事情在合法的应用程序上是不可能的。

我知道,因为我问了同样的问题: iPhone 能否检测到触摸的大小?

It's not possible with the SDK. It does not expose that data in anyway. And the screen does not sense pressure, and wether it even reports touch "size" to the OS is unknown. So sadly, what you are trying to do is not possible on a legit application.

I know because I asked the same thing: Can the iPhone detect the size of a touch?

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