在进入编辑模式时动画自定义绘制的UITableViewCell [英] Animating custom-drawn UITableViewCell when entering edit mode

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

问题描述

首先,非常感谢 atebits ,他们的信息非常丰富的博文快速滚动Tweetie与UITableView 。该帖子详细解释了开发人员如何通过 Tweetie中的UITableViews尽可能多地滚动滚动效果

First of all, much gratitude to atebits for their very informative blog post Fast Scrolling in Tweetie with UITableView. The post explains in detail how the developers were able to squeeze as much scrolling performance as possible out of the UITableViews in Tweetie.

从博客文章链接的源代码开始=http://atebits.cachefly.net/blog/FastScrolling/FastScrolling.zip =nofollow noreferrer>原始)( my github repo ):

Beginning with the source code linked from the blog post (original) (my github repo):


  1. UITableView使用这些自定义单元格切换到编辑模式,暴露UI从表中删除项目。 ( github commit

将单元格的文本移动到删除控件从左侧滑入时。这是完整的,虽然文本来回没有动画。 ( github commit

Move the cell's text aside as the deletion control slides in from the left. This is complete, although the text jumps back and forth without animation. (github commit)

将动画应用于上述目标2中的文字运动,获得流畅的用户体验。



问题



介绍这个动画完成目标3的最好方法是什么?这将是很好,如果这可以保持逻辑从我的最后提交,因为我会喜欢仅移动视图的冲突部分的选项,而任何非冲突部分(例如右对齐文本)保持在同一位置或移动不同数量的像素。如果上面是不可能的,然后撤消我的最后一个提交,并将其替换为一个选项,将整个视图滑动到右边也将是一个可行的解决方案。

The Question

What is the best way to introduce this animation to complete goal 3? It would be nice if this could be done in a manner that keeps the logic from my last commit because I would love the option to move the conflicting part of the view only, while any non-conflicting portions (such as right-justified text) stay in the same place or move a different number of pixels. If the above is not possible then undoing my last commit and replacing it with an option that slides the entire view to the right would be a workable solution also.

帮助任何人可以提供,从快速指针和想法一直到代码片段或github提交。当然,如果您愿意,欢迎您我的回购。我将保持参与这个问题,以确保任何成功的决议致力于github和完整的文档在这里。非常感谢您的时间!

I appreciate any help anyone can provide, from quick pointers and ideas all the way to code snippets or github commits. Of course you are welcome to fork my repo if you would like. I will be staying involved with this question to make sure any successful resolution is committed to github and fully documented here. Thanks very much for your time!

并且意识到在视图中移动一些文本项相对于其他文本项可以撤消在原始博客文章中解决的一些原始性能目标。所以在这一点上,我想一个解决方案,整个单个子视图动画到新的位置可能是最好的。

I have been thinking about this a lot since my first post and realized that moving some text items relative to others in the view could undo some of the original performance goals solved in the original blog post. So at this point I am thinking a solution where the entire single subview is animated to its new postion may be the best one.

第二,如果这样做可能存在其中子视图具有自定义颜色或渐变背景的实例。希望这可以这样做,在正常位置背景延伸到左边不足,使得当视图向右滑动时,自定义背景在整个单元格仍然可见。

Second, if it is done in this way there may be an instance where the subview has a custom color or gradient background. Hopefully this can be done in a way that in its normal position the background extends unseen off to the left enough so that when the view is slid to the right the custom background is still visible across the entire cell.

推荐答案

感谢 Craig的回答,这指向我的方向正确,我有一个解决方案。我还原了我的提交,它根据编辑模式移动了文本位置,并替换了它与一个新的解决方案,将整个内容视图设置到正确的位置任何时间layoutSubviews被调用,这导致在切换到编辑模式和从编辑模式切换时的自动动画:

Thanks to Craig's answer which pointed me in the right direction, I have a solution for this. I reverted my commit which moved the text position based on the editing mode and replaced it with a new solution that sets the entire content view to the correct position any time layoutSubviews is called, which results in an automatic animation when switching to and from edit mode:

- (void)layoutSubviews
{
    CGRect b = [self bounds];
    b.size.height -= 1; // leave room for the separator line
    b.size.width += 30; // allow extra width to slide for editing
    b.origin.x -= (self.editing) ? 0 : 30; // start 30px left unless editing
    [contentView setFrame:b];
    [super layoutSubviews];
}



通过这样做我可以删除setFrame:override ABTableViewCell.m因为它的前逻辑加我的添加现在在layoutSubviews中找到。

By doing it this way I was able to remove the setFrame: override found in ABTableViewCell.m because its former logic plus my additions are now found in layoutSubviews.

我在单元格上设置浅灰色背景,以验证自定义背景是否正常工作,而不允许我们看到它背后来回移动,它似乎工作很好。

I set a light grey background on the cells to verify a custom background works properly without allowing us to see behind it as it moves back and forth and it seems to work great.

再次感谢Craig和其他任何研究这个问题的人。

Thanks again to Craig and anyone else who has looked into this.

GitHub提交此解决方案: (链接

GitHub commit for this solution: (link)

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

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