动画UITableViewCell ContentView在进入编辑模式时淡出 [英] Animate UITableViewCell ContentView to fade upon entering Edit Mode

查看:97
本文介绍了动画UITableViewCell ContentView在进入编辑模式时淡出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在iPhone Mail.app和SMS.app应用程式中注意到这项功能,但我不确定如何自行实作。

I've noticed this functionality in the iPhone Mail.app and SMS.app apps, but I'm unsure how to implement it myself.

UITableView,当用户点击编辑按钮并且删除按钮移动到位置时,内容视图向右滑动,他们执行快速褪色转换,在那里他们被自己的较薄版本替换(为了占用空间

In a standard UITableView, when a user taps the 'Edit' button and the deletion buttons move into position, as the content views are sliding to the right, they perform a quick fade transition where they are replaced by thinner versions of themselves (to account for the space the deletion button is taking up).

我最初认为这是通过在编辑模式启用时调用以下方法完成的:

I initially thought this was done by calling the following method when editing mode is enabled:

[self.tableView reloadRowsAtIndexPaths: [tableView indexPathsForVisibleRows] withRowAnimation: UITableViewRowAnimationFade];

然而,这不能是正确的,因为它也淡化转换删除按钮本身以及任何附件视图细胞有(足够说,它看起来很奇怪)。

However this cannot be right as it also fade transitions the delete button itself as well as any accessory views the cell has (suffice it to say, it looks quite odd).

我想知道,如何强制内容视图重绘本身,然后

I was wondering, how would it be possible to force the content view to redraw itself, and to then fade the new drawn version over the old one when the table enters edit mode?

更新:
感谢Caleb的回答,这是最后的代码块允许我获得我的后:

UPDATE: Thanks to Caleb's answer, this is the final block of code that allowed me to get what I was after:

我的最终解决方案是子类化UITableViewCell,然后应用以下代码到setEditing访问器:

My final solution was to subclass UITableViewCell and then apply the following code to the setEditing accessor:

-(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];
    }
}

我可能应该澄清一下。由于性能至关重要,我的单元格内容视图中的所有内容都是通过CG(即drawRect :)渲染的,所以我不能控制任何在那里绘制的元素。

I probably should just clarify as well. Since performance is of utmost importance, everything inside my cell's contentView is being rendered through CG (ie drawRect:), so I can't control any elements being drawn in there specifically.

推荐答案

当你在表上调用 -setEditing:animated:时,然后,表在每个可见单元格上调用 -setEditing:animated:。看起来,表单元格的标准行为是调整内容视图的大小,将它们向右移动,并删除正确的附件。如果你有自己的单元格,并希望在编辑模式不同的外观,我想你可以覆盖 -setEditing:animated:根据需要调整单元格内容。

That animation happens when you call -setEditing:animated: on the table. The table then calls -setEditing:animated: on each of the visible cells. It looks like the standard behavior for a table cell is to adjust the size of the content views, shift them right, and remove the right accessory. If you have your own cells and want a different look in editing mode, I think you can override -setEditing:animated: to adjust the cell content as you like.

这篇关于动画UITableViewCell ContentView在进入编辑模式时淡出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆