有什么方法可以让我知道按屏幕的力度有多大
我想找到触摸的压力。我只是不知道如何在不越狱并获取原始触摸数据的情况下实现该结果。有谁知道我会怎么做?
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您无法从 SDK 或未记录的方法中获得压力。但是,您可以使用未记录的方法检测触摸的大小。
在 GSEvent(UIEvent 的较低级别表示)中,有一个名为 GSPathInfo 与成员:
我们注意到有一个
pathPressure
和pathMajorRadius
。我可以向您保证压力构件是无用的 - 它总是给出 0。但是pathMajorRadius
确实包含有意义的信息 - 它给出了触摸的主半径(以毫米为单位)。因此,您可以对半径上是重接触还是轻接触给出极其粗略的估计。让我再次警告您,这是未记录的,您不应该在 AppStore 应用程序中使用它。
编辑:在 3.2 及更高版本中,GSPathInfo 的
pathMajorRadius
也可以作为 UITouch 中的未记录属性:因此可以使用纯 Objective-C 重写上面的代码:
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:
We notice that there is a
pathPressure
andpathMajorRadius
. I can assure you the pressure member is useless – it always gives 0. HoweverpathMajorRadius
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.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:so the code above could be rewritten using pure Objective-C:
从 iOS 8.0 开始,
UITouch
有一个公共majorRadius
属性,可以告诉您触摸的大致大小。As of iOS 8.0,
UITouch
has a publicmajorRadius
property which tells you the approximate size of the touch.在 iOS 3.2 和 4.0 中,您可以像这样更直接地获取值:
仍然没有 App Store 批准,但对于自定义内容很方便。
In iOS 3.2 and 4.0 you can get the value more directly like this:
Still not App Store approved, but handy for custom stuff.
使用 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?