Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/93.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Cocoa touch 设置UITableViewCell ContentView动画,使其在进入编辑模式时淡入淡出_Cocoa Touch_Ios_Uitableview_Uikit - Fatal编程技术网

Cocoa touch 设置UITableViewCell ContentView动画,使其在进入编辑模式时淡入淡出

Cocoa touch 设置UITableViewCell ContentView动画,使其在进入编辑模式时淡入淡出,cocoa-touch,ios,uitableview,uikit,Cocoa Touch,Ios,Uitableview,Uikit,我在iPhone Mail.app和SMS.app应用程序中注意到了这一功能,但我不确定自己如何实现它 在标准UITableView中,当用户点击“编辑”按钮且删除按钮移动到位时,内容视图向右滑动时,它们会执行快速淡入过渡,被较薄版本的内容视图替换(考虑删除按钮占用的空间) 我最初认为这是通过在启用编辑模式时调用以下方法实现的: [self.tableView reloadRowsAtIndexPaths: [tableView indexPathsForVisibleRows] withRow

我在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:)进行渲染的,因此我无法具体控制在其中绘制的任何元素。

当您在表上调用
-setEditing:animated:
时,动画就会发生。然后,该表在每个可见单元格上调用
-setEditing:animated:
。看起来表格单元格的标准行为是调整内容视图的大小,将其向右移动,然后卸下右侧附件。如果您有自己的单元格,并且希望在编辑模式下具有不同的外观,我认为您可以覆盖
-setEditing:animated:
,以根据需要调整单元格内容

我不确定这是否涵盖了它。当已经处于编辑模式的行显示其删除按钮(状态==3)时,上述应用程序使用相同的转换。发生这种情况时,不会调用setEditing:animated:。