0
在我的應用程序中,我想要檢測用戶何時擡起第二根手指,並且只握住屏幕上的一個。iPhone:如何檢測哪個觸摸已結束?
的問題是,我的touchesEnded:withEvent:方法顯示[事件allTouches]數]爲2
我如何能夠檢測觸摸的一個保留在屏幕上?
謝謝。
在我的應用程序中,我想要檢測用戶何時擡起第二根手指,並且只握住屏幕上的一個。iPhone:如何檢測哪個觸摸已結束?
的問題是,我的touchesEnded:withEvent:方法顯示[事件allTouches]數]爲2
我如何能夠檢測觸摸的一個保留在屏幕上?
謝謝。
當觸摸由用戶touchesBegan方法觸發。你可以保持指針第一次觸摸出現。在觸摸結束之前它不會被改變。
編輯:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
if ([touches count] == 1)
{
if (!myTouch) myTouch = [touches anyObject]; //I assume myTouch is set to nil in touchesEnded
}
else
{
//perform your logic for this case
}
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
if (myTouch && [touches containsObject: myTouch]
{
//perform your logic
myTouch = nil;
}
}
我假設你有你的類來處理觸摸事件的變量UITouch *myTouch
。
你能舉個例子嗎? – CristiC 2011-02-25 23:01:25
@Parkyprg:我已經更新了答案 – Andrew 2011-02-25 23:16:21