Я добавил устройства распознавания жестов с одним или двумя касаниями в 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, т.е. нажатие на кнопку отмены не распознано.
Я бы оценил любые мысли, спасибо.