這是一個針對客戶端的項目,他希望它使用TouchesBegan/Moved/Ended而不是手勢,因爲它必須與iOS 3.0和3.1兼容並且手勢是iOS> = 3.2。iPhone - 在iOS 3.x上檢測單點擊和長時間點擊
我必須檢測一個自定義元素上的單擊和長按,這是一種tableView元素,我們稱之爲單元格。
我必須遵循的規則是:
- 單抽頭爲0.1秒後到火的方法(可以稱之爲cellTapped)
- 如果控制被滾動之前,它是時間來執行cellTapped相反,如果檢測到長按,取消cellTapped執行
- ,運行不cellTapped
這個longTap方法是我在的touchesBegan
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
self.isScrolling = NO;
// if single tap detected, fire method within 0.1 seconds
if ([self elementIsTapped:touches]) {
[self performSelector:@selector(cellTapped:)
withObject:nil
afterDelay:0.1];
}
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
if (self.isScrolling == NO) {
// started scrolling, cancel single tap method that was about to be executed
[NSObject cancelPreviousPerformRequestsWithTarget:self
selector:@selector(cellTapped:)
object:nil];
self.isScrolling = YES;
}
}
如何將長時間檢測添加到此邏輯?謝謝
這顯然不是一個有用的答案,但爲什麼你需要支持iOS 3.x? – jonmorgan
實現'touchesEnded'並計算'開始'和'結束'之間的時間差,並將這個時間差用於您的單觸或長觸式情況。 – Legolas
據我所知,這個項目在公司內部使用,他有很多舊設備,運行3.0,他希望這些設備運行應用程序。我知道,我知道,但是感覺到我的痛苦... – SpaceDog