首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >LongPress上的UITableViewCell闪烁

LongPress上的UITableViewCell闪烁
EN

Stack Overflow用户
提问于 2012-03-09 18:51:28
回答 1查看 2.1K关注 0票数 3

我有一个UITableView,在它的UITableViewCell%s中添加了一个UILongPressGestureRecognizer,如下所示:

代码语言:javascript
复制
// Setup Event-Handling
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleTableViewCellLongPress:)];

[cell addGestureRecognizer:longPress];

[longPress setDelegate:self];

我希望细胞在事件被触发时闪烁,我也希望禁止标准行为(按下一次它就会变成蓝色)。

如何在我的handleTableViewCellLongPress-Method中执行此操作?

谢谢!

EN

回答 1

Stack Overflow用户

发布于 2012-03-09 20:48:26

你可以使用链接动画:

代码语言:javascript
复制
- (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) {

    }];
  }];
}
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9632815

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档