【发布时间】:2011-12-13 02:58:05
【问题描述】:
我无法获得UIView 以通过多次触摸来响应我想要的方式。基本上确定UITouches 在UITouchPhaseBegan,但永远不会到达UITouchPhaseEnded 或UITouchPhaseCancelled。这是我用来处理触摸的代码,从touchesBegan:withEvent、touchesMoved:withEvent、touchesEnded:withEvent 和touchesCancelled:withEvent 调用。如果我将一根手指向下,然后另一根,同时移动它们并释放它们,NSLog 输出有时开始!开始了!结束了!而不是开始了!开始了!结束了!结束!。这些触摸是否在某个地方丢失了?如何跟踪它们?
- (void) handleTouchEvent:(UIEvent *)event {
for( UITouch* touch in [event allTouches] ) {
if( touch.phase == UITouchPhaseBegan ) {
NSLog(@"Began!");
if( ![m_pCurrentTouches containsObject:touch] )
[m_pCurrentTouches addObject:touch];
uint iVoice= [m_pCurrentTouches indexOfObject:touch];
CGPoint location = [touch locationInView:self];
m_pTouchPad->SetTouchPoint( location.x, location.y, iVoice );
m_pTouchPad->SetIsTouching( true, iVoice );
}
else if( touch.phase == UITouchPhaseMoved ) {
uint index= [m_pCurrentTouches indexOfObject:touch];
CGPoint location = [touch locationInView:self];
m_pTouchPad->SetTouchPoint( location.x, location.y, index );
}
else if( touch.phase == UITouchPhaseEnded || touch.phase == UITouchPhaseCancelled ) {
uint index= [m_pCurrentTouches indexOfObject:touch];
[m_pCurrentTouches removeObject:touch];
NSLog(@"Ended!");
m_pTouchPad->SetIsTouching( false, index );
}
}
}
编辑:
我提供赏金是因为我真的想要一个好的解决方案。总结一下:我需要一个开始的每次触摸也结束的系统,所以如果用户放下一根手指,然后在别处放下另一根手指,我可以看到两个触摸都开始了,当没有手指的时候不再与设备接触,我已经看到两次触摸都结束了。
我是否采取了错误的策略来实现这一目标?
【问题讨论】:
-
为什么你使用
[event allTouches]而不是touches传递自touchesBegan:withEvent?
标签: ios uiview multi-touch uitouch touches