UITableViewCellsにシングルタップおよびダブルタップのジェスチャ認識機能を追加しました。しかし、テーブルを数回スクロールした後、テーブルをスクロールするためのスワイプジェスチャが終了してから、スクロールアニメーションが開始されるまでの休止時間がますます長くなります。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"tableViewCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
UITapGestureRecognizer* singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTap:)];
singleTap.numberOfTapsRequired = 1;
singleTap.numberOfTouchesRequired = 1;
[cell addGestureRecognizer:singleTap];
UITapGestureRecognizer* doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doubleTap:)];
doubleTap.numberOfTapsRequired = 2;
doubleTap.numberOfTouchesRequired = 1;
[singleTap requireGestureRecognizerToFail:doubleTap];
[cell addGestureRecognizer:doubleTap];
if (tableView == self.searchDisplayController.searchResultsTableView) {
// search results
}
else {
// normal table
}
return cell;
}
SingleTap:およびdoubleTap:メソッド
- (void)singleTap:(UITapGestureRecognizer *)tap
{
if (UIGestureRecognizerStateEnded == tap.state) {
UITableViewCell *cell = (UITableViewCell *)tap.view;
UITableView *tableView = (UITableView *)cell.superview;
NSIndexPath* indexPath = [tableView indexPathForCell:cell];
[tableView deselectRowAtIndexPath:indexPath animated:NO];
// do single tap
}
}
- (void)doubleTap:(UITapGestureRecognizer *)tap
{
if (UIGestureRecognizerStateEnded == tap.state) {
UITableViewCell *cell = (UITableViewCell *)tap.view;
UITableView *tableView = (UITableView *)cell.superview;
NSIndexPath* indexPath = [tableView indexPathForCell:cell];
[tableView deselectRowAtIndexPath:indexPath animated:NO];
// do double tap
}
}
最初のスクロールはスムーズなので、ジェスチャー認識機能をif (cell == nil)
条件に追加しようとしましたが、セルに追加されることはありませんでした。
また、最初は個々のセルではなくジェスチャをtableViewに追加しましたが、これによりsearchDisplayControllerで問題が発生しました。つまり、キャンセルボタンをタップしても認識されません。
どんな考えでも感謝します、ありがとう。