我有一段简单的代码,其中我重写了touchesBegan、and、Cancelled(空块)和touchesMoved。如果我用鼠标touchesBegan点击(我是在桌面PC上测试),它就会被调用,但是只有当我移动手指一段时间时才会调用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()
}
}发布于 2015-02-26 11:12:26
我确信这是一个仿真器问题。
请看下面的代码。它就像我那头的魅力。
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
didMove = false;
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
didMove = true;
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
if (didMove == true)
{
//finger was moved
NSLog(@"finger was moved");
}
else
{
//it's a tap
NSLog(@"finger not moved it's a tap");
}
}当我们正在做的时候,我能让你注意到UIGestureRecognizers吗?试着使用它们,因为它们使生活变得轻而易举。
https://stackoverflow.com/questions/28740295
复制相似问题