2010-01-28 152 views
4

在這些方法中,我獲得相應的階段:
的touchesBegan:withEvent:方法UITouchPhaseBegan,
touchesMoved:withEvent:方法UITouchPhaseMoved,
touchesEnded:withEvent:方法UITouchPhaseEnded,
touchesCancelled:withEvent:方法UITouchPhaseCancelled。我在哪裏可以通過階段UITouchPhaseStationary獲得觸摸事件?

我在哪裏可以得到這個階段的觸摸事件:UITouchPhaseStationary

回答

2

您可以假設在2 Moved事件之間的時間觸摸爲靜止。

UITouchPhaseStationary存在,因爲多點觸控的。如果一個手指的移動而其他沒有,仍然引發了Moved事件,但靜止觸摸將在階段UITouchPhaseStationary。)

+0

您是否通過實驗或某些文檔知道這一點? – yehnan 2010-01-28 11:01:38

+0

@yehnan:文檔。我想大多數iPhoneOS編程教程都會談論這個。 – kennytm 2010-01-28 11:12:15

+0

哦,我知道。但教程通常只提到一兩句話。謝謝。 – yehnan 2010-01-28 11:20:28

0

是的,你可以。但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]) ; 
    } 

} 
相關問題