【发布时间】:2016-11-17 21:50:23
【问题描述】:
我正在使用 Swift 3 和 Xcode
我有以下课程:
class Finger: UITouch
{
var firstTimeStamp: TimeInterval = 0.0
}
还有这个变量:
var finger: Finger?
这是我的touchesBegan 函数:
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?)
{
if finger == nil
{
let touch = touches.first
finger = touch as! GameScene.Finger? <--- ERROR
finger?.firstTimeStamp = finger!.timestamp
}
}
它可以构建,但是当我触摸屏幕时出现此错误:
Could not cast value of type 'UITouch' (0x10f3b1ca8) to 'Project.GameScene.Finger' (0x10c3f71a0).
我想知道手指在屏幕上的时间,从 touchesBegan 到 touchesEnded。这是最好的方法吗? 无论如何,我做错了什么?
【问题讨论】:
标签: swift timestamp uitouch touchesbegan nstimeinterval