是的,你可以。但iOS 不發送觸摸靜止手指事件。正如@KennyTM所說的,無論什麼時候任何其他4種類型的動作發生,它們實際上都會出現在allTouches
對象的數組中。
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]) ;
}
}
您是否通過實驗或某些文檔知道這一點? – yehnan 2010-01-28 11:01:38
@yehnan:文檔。我想大多數iPhoneOS編程教程都會談論這個。 – kennytm 2010-01-28 11:12:15
哦,我知道。但教程通常只提到一兩句話。謝謝。 – yehnan 2010-01-28 11:20:28