我在 iPhone Mail.app 和 SMS.app 应用程序中注意到了此功能,但我不确定如何自己实现它。
在标准 UITableView 中,当用户点击“编辑”按钮并且删除按钮移动到位时,随着内容视图向右滑动,它们会执行快速淡入淡出过渡,并被自身的更薄版本所取代(考虑到删除按钮占用的空间)。
我最初认为这是通过在启用编辑模式时调用以下方法来完成的:
[self.tableView reloadRowsAtIndexPaths: [tableView indexPathsForVisibleRows] withRowAnimation: UITableViewRowAnimationFade];
然而,这不可能是正确的,因为它还会淡入淡出过渡删除按钮本身以及单元格具有的任何附件视图(可以说,它看起来很奇怪)。
我想知道,如何强制内容视图重新绘制自身,然后在表格进入编辑模式时使新绘制的版本淡入旧版本?
更新:
感谢 Caleb 的回答,这是最后的代码块,使我能够得到我想要的东西:
我的最终解决方案是子类化 UITableViewCell ,然后将以下代码应用于 setEditing 访问器:
-(void) setEditing: (BOOL)editing animated: (BOOL)animated
{
[super setEditing: editing animated: animated];
CATransition *animation = [CATransition animation];
animation.duration = 0.2f;
animation.type = kCATransitionFade;
//redraw the subviews (and animate)
for( UIView *subview in self.contentView.subviews )
{
[subview.layer addAnimation: animation forKey: @"editingFade"];
[subview setNeedsDisplay];
}
}
我可能也应该澄清一下。由于性能是最重要的,所以我的单元格 contentView 内的所有内容都是通过 CG(即 drawRect:) 渲染的,因此我无法控制其中具体绘制的任何元素。