然而,一些应用程序似乎已经使用了这个函数调用:
- Penultimate实现了真正的手掌拒绝,而不像Note Taker HD那样需要预定义的拒绝区域
- Virtuoso实现了压感,他们称之为“TrueVelocity 2”
- GarageBand也实现了压感
在iOS8中,你可以访问 touch.majorRadius
属性,它是一个 CGFloat
类型,以10.45的倍数增长,并且与所触摸区域的半径成比例(单位为毫米)。touch.majorRadiusTolerance
是第二个可以在iOS8中使用的属性,它提供了触摸半径信息的精确度。在我的测量中,它总是 majorRadius
步长的一半。
在iPad Pro上,触摸屏幕比旧款iPad模型更加敏感,并能够捕捉到Apple Pencil发出的微弱信号,而这些信号在旧款iPad模型上都低于报告阈值。Pencil的触摸半径报告为0.25,而即使是轻微的手指触摸也会报告20.84或更多。
在您的UIView方法中像这样使用:
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
// Regular multitouch handling.
[super touchesBegan:touches withEvent:event];
CGPoint center = [touch locationInView:self];
NSLog(@"Touch detected at %6.1f | %6.1f", center.x, center.y);
CGFloat radius = [touch majorRadius];
NSLog(@"Radius = %5.1f; lower limit = %5.1f; upper limit = %5.1f", radius, radius-touch.majorRadiusTolerance, radius+touch.majorRadiusTolerance);
}
大小和压力是两个不同的概念。Penultimate很可能会测试某个区域内大量触摸事件(毕竟手掌面积很大,会产生大量触摸事件)。
触摸“大小”并不存在。IOS触摸事件在手指接触屏幕时生成。然后操作系统从触摸中心点获取信息,这就是你得到的内容。它不是CGRect,而是CGPoint。
压力相对“容易”。这里提供了一种解决方法:使用加速计检测轻按压力
此外,虽然我看到您正在寻找私有API,但github上托管了许多类转储:http://github.com/kennytm/iphone-private-frameworks 和 https://github.com/nst/iOS-Runtime-Headers
如果您对私有方法(即不将其提交到应用商店的方法)感兴趣,您正在寻找的是 -
@interface UITouch (Private)
-(float)_pathMajorRadius;
@end
10
是一个很好的阈值,用于确定一个人是在用手指/触控笔还是将手放在设备上。提供信息,iOS 8 引入了一些属性来估算 UITouch
的半径: majorRadius
和 majorRadiusTolerance
。
https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITouch_Class/index.html