我有UITableView
,UITableViewCell
我正在添加UILongPressGestureRecognizer
这样的内容:
// Setup Event-Handling
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleTableViewCellLongPress:)];
[cell addGestureRecognizer:longPress];
[longPress setDelegate:self];
我希望在事件被触发时单元格会闪烁,我也想禁止标准行为(按下一次它会变成蓝色)。
我如何在handleTableViewCellLongPress
- 方法?
谢谢!
答案 0 :(得分:4)
您可以使用链接动画:
- (UITableViewCell *) tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = ...
// remove blue selection
cell.selectionStyle = UITableViewCellSelectionStyleNone;
UILongPressGestureRecognizer *gesture = [[[UILongPressGestureRecognizer alloc]
initWithTarget:self action:@selector(handleTableViewCellLongPress:)] autorelease];
[cell addGestureRecognizer:gesture];
return cell;
}
- (void) handleTableViewCellLongPress:(UILongPressGestureRecognizer *)gesture
{
if (gesture.state != UIGestureRecognizerStateBegan)
return;
UITableViewCell *cell = (UITableViewCell *)gesture.view;
[UIView animateWithDuration:0.1 animations:^{
// hide
cell.alpha = 0.0;
} completion:^(BOOL finished) {
// show after hiding
[UIView animateWithDuration:0.1 animations:^{
cell.alpha = 1.0;
} completion:^(BOOL finished) {
}];
}];
}