Where can I get a touch event with phase UITouchPhaseStationary?
In these methods, I get corr开发者_如何学Pythonesponding phases:
touchesBegan:withEvent: UITouchPhaseBegan, touchesMoved:withEvent: UITouchPhaseMoved, touchesEnded:withEvent: UITouchPhaseEnded, touchesCancelled:withEvent: UITouchPhaseCancelled.Where can I get a touch event with this phase: UITouchPhaseStationary?
You can assume a touch in the time between 2 Moved
events as stationary.
(UITouchPhaseStationary
exists because of multitouch. If one finger moves while the other doesn't, a Moved
event is still triggered, but the stationary touch will be in the phase UITouchPhaseStationary
.)
Yeah, you can. but iOS doesn't send touch stationary finger events. As @KennyTM said, they actually come in the allTouches
array of the UIEvent
object whenever any of the other 4 types of touchevents occur.
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] ) ;
}
}
More information, for example currently I have 3 fingers down. If one of them moves, then -(void) touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
will triggers but there is only one touch in touches
and that only one touch has a phase of UITouchPhaseMoved
.
If you want 3 touches of moved, stationary, stationary phases then you need to check [event allTouches]
. (Has the same (NSSet<UITouch *> *)
type as touches
) The touches
only contains the touch that trigger the callback and thus you never get stationary phase out of touches
because there is no such callback for stationary (holding still) input.
精彩评论