【发布时间】:2015-02-26 10:43:53
【问题描述】:
我有一段简单的代码,其中我覆盖了 touchesBegan、Ended、Cancelled(空块)和 touchesMoved。 如果我用鼠标点击(我正在台式电脑上测试)touchesBegan 它被调用,但 touchesEnded 仅在我移动手指一段时间时被调用。这使得无法识别手指的单击或拖动,并以不同的方式处理它们。 我不明白这是模拟器问题还是我误解了整个过程。你有同样的问题吗?
我的应用程序有一个简单的解决方案,例如检查 touchesBegan 中的“第一步”变量,但这是一个纯技术问题。
提前谢谢你。
这就是我使用的所有东西,除了 drawRect 这并不重要。 我想这在我的代码中不是问题。
override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
let touch = touches.allObjects[0] as UITouch
let touchPoint = touch.locationInView(self)
println("touchesBegan")
if (Draw!){
path.moveToPoint(touchPoint)
path.addLineToPoint(touchPoint)
self.setNeedsDisplay()
}
}
override func touchesMoved(touches: NSSet, withEvent event: UIEvent) {
let touch = touches.allObjects[0] as UITouch
let touchPoint = touch.locationInView(self)
println("touchesMoved")
if (Draw!){
path.addLineToPoint(touchPoint)
self.setNeedsDisplay()
}
}
override func touchesEnded(touches: NSSet, withEvent event: UIEvent) {
let touch = touches.allObjects[0] as UITouch
let touchPoint = touch.locationInView(self)
println("touchesEnded")
if (Draw!){
path.addLineToPoint(touchPoint
path = UIBezierPath() // Create new path for next line
self.setNeedsDisplay()
}
}
【问题讨论】:
-
请您分享您为此使用的代码。