斯威夫特:记录触摸力,大小,持续时间

问题描述 投票:0回答:1

对于数据分析项目,我想在一个简单的应用程序的日志文件中跟踪触摸力,大小和持续时间的测量值(我使用Apple文档网站上的Foodtracker app)。

我知道我可以从UITouch获得forcesizeduration。但

  1. 如何访问UITouch进行这些测量?
  2. 以及如何将这些测量值写入日志文件?
ios swift iphone uitouch
1个回答
0
投票

1. How do I access UITouch to get these measurements?

您必须覆盖视图控制器中的触摸处理程序。

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

2. How do I write these measurements into a log-file?

对于那个结帐这篇文章:Read and write a String from text file

© www.soinside.com 2019 - 2024. All rights reserved.