我无法UIView
通过多次触摸来响应我想要的方式。基本上某些UITouch
es 在UITouchPhaseBegan
但永远不会进入UITouchPhaseEnded
or UITouchPhaseCancelled
。这是我用来处理触摸的代码,从、touchesBegan:withEvent
和调用。如果我将一根手指向下,然后另一根手指,同时移动它们并释放它们,输出有时是Began!开始了!结束了!而不是开始!开始了!结束了!结束了!. 这些触摸是否在某个地方丢失了?我怎样才能跟踪他们?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 );
}
}
}
编辑:
我提供赏金是因为我真的想要一个好的解决方案。总结一下:我需要一个系统,每次开始的触摸都会结束,所以如果用户放下一根手指,然后在别处放下另一根手指,我可以看到两个触摸都开始了,当没有手指与设备接触时,我已经看到这两种接触都结束了。
我是否采取了错误的策略来实现这一目标?