【发布时间】:2019-03-09 11:14:34
【问题描述】:
对于数据分析项目,我想在一个简单应用程序的日志文件中跟踪触摸力、大小和持续时间的测量结果(我使用 Apple 文档网站上的 Foodtracker app)。
我知道我可以从 UITouch 获得 force、size 和 duration。但是
- 如何访问 UITouch 以获取这些测量值?
- 以及如何将这些测量值写入日志文件?
【问题讨论】:
对于数据分析项目,我想在一个简单应用程序的日志文件中跟踪触摸力、大小和持续时间的测量结果(我使用 Apple 文档网站上的 Foodtracker app)。
我知道我可以从 UITouch 获得 force、size 和 duration。但是
【问题讨论】:
您必须覆盖视图控制器中的触摸处理程序。
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesBegan(touches, with: event)
let touch = touches.first!
print("\(touch.force)")
print("\(touch.majorRadius)")
print("\(touch.timestamp)")
}
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesMoved(touches, with: event)
let touch = touches.first!
print("\(touch.force)")
print("\(touch.majorRadius)")
print("\(touch.timestamp)")
}
override func touchesCancelled(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesCancelled(touches, with: event)
let touch = touches.first!
print("\(touch.force)")
print("\(touch.majorRadius)")
print("\(touch.timestamp)")
}
【讨论】:
super.touchesBegan(touches, with: event)
UIViewController 的类继承并且也使用这些方法时才需要。