在这些方法中,我得到了相应的阶段:
touchesBegan:withEvent:UITouchPhaseBegan,
touchesMoved:withEvent:UITouchPhaseMoved,
touchesEnded:withEvent:UITouchPhaseEnded,
touchesCancelled:withEvent:UITouchPhaseCancelled。
在这个阶段我可以在哪里获得触摸事件: UITouchPhaseStationary ?
答案 0 :(得分:3)
您可以假设在2 Moved
个事件之间的时间触摸为静止。
(UITouchPhaseStationary
因多点触控而存在。如果一个手指移动而另一个手指不移动,则仍会触发Moved
事件,但静止触摸将处于阶段UITouchPhaseStationary
。)
答案 1 :(得分:1)
allTouches
对象的UIEvent
数组。
const char* touchPhaseName[] = {
"UITouchPhaseBegan", // whenever a finger touches the surface.
"UITouchPhaseMoved", // whenever a finger moves on the surface.
"UITouchPhaseStationary", // whenever a finger is touching the surface but hasn't moved since the previous event.
"UITouchPhaseEnded", // whenever a finger leaves the surface.
"UITouchPhaseCancelled"
} ;
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
for( UITouch* touch in event.allTouches )
{
// event.allTouches INCLUDES the other fingers, some of which may still be stationary
printf( "Touch id=%d is in phase %s\n", touch, touchPhaseName[touch.phase] ) ;
}
}
答案 2 :(得分:0)
更多信息,例如当前我有3个手指在下。如果其中之一移动,则将触发-(void) touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
,但是 touches
中只有一次触摸,并且只有一次触摸的相位为UITouchPhaseMoved
。>
如果要移动,固定,固定相进行3次触摸,则需要检查[event allTouches]
。 (与(NSSet<UITouch *> *)
具有相同的touches
类型)touches
仅包含触发回调的触摸,因此您永远不会从touches
中退出固定相位,因为没有这样的相位固定(保持静止)输入的回调。