UITableView框架更改动画问题 [英] UITableView frame change animation issue

查看:80
本文介绍了UITableView框架更改动画问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经搜索了很多这个问题,但似乎没有答案。所以我希望你们中的一些人知道如何解决这个问题。我有一个具有tableview的视图控制器,当我用动画更改视图框架时,一切顺利,除了一个特殊情况,当tableview有更多项目而不是它适合屏幕时,并且只有当tableview滚动到底部时。然后,如果我缩小视图高度,我的视图正确动画,但是tableview以某种方式跳了一下,然后才动画到底部。

I've googled about this problem a lot but there seems to be no answer. So I'm hoping some of you may know how to deal with this. I have a view controller that has a tableview, when I change the view frame with animation, everything goes well, except one particular case, when tableview has more items than it can fit to screen, and only when the tableview is scrolled to bottom. Then if I shrink the view height, my view animates correctly, but the tableview somehow jumps up a bit and only then animates to the bottom.

如果我缩小视图,但是tableview没有滚动到底部(即使我可以看到最后一个单元格,让我们说它的一半多一点)它可以正确地设置动画。

If I shrink the view, but tableview isn't scrolled to bottom (even if I can see the last cell, lets say a bit more than half of it) it does animate correctly.

我'尝试了几件事,比如开启和关闭自动调整面具,以及从当前状态或类似的东西动画,但这没有帮助:/

I've tried couple of things, like setting autoresizing masks on and off and also animate from current state or something like that, but that didn't help :/

所以任何建议可能是什么问题?

So any suggestions what could be the problem?

编辑:

我用的代码更改框架

[UIView animateWithDuration:0.5
                          delay:0.0
                        options: UIViewAnimationCurveEaseOut
                     animations:^{

                         [_contView setFrame:CGRectMake(0, 0, 320, 420)];
                     } 
                     completion:^(BOOL finished){

                     }];


推荐答案

我曾经有过类似的问题我实现了这个解决方法(免责声明:这是对当前尚未解决的iOS错误的攻击):

I used to have a similar problem and I implemented this workaround (Disclaimer: this is a hack to a currently-unresolved iOS bug):

// check if the table view is scrolled to the bottom
if (tableView.contentOffset.y + tableView.frame.size.height == tableView.contentSize.height) {
    // if it is, shift the table view contents up one pixel
    [tableView setContentOffset:CGPointMake(tableView.contentOffset.x, tableView.contentOffset.y - 1) animated:NO];
}

// call the animation block afterwards here

这是一个黑客,虽然用户不明显,因为它只是一个1像素的运动。 UITableView有一些错误(已向Apple报告,但尚未解决),当涉及到从滚动到底部位置的动画时。

It's a hack, though not noticeable to the user since it's just a 1 pixel motion. UITableView has a few bugs (reported to Apple already, but not yet resolved) when it comes to animations from a scrolled-to-bottom position.

这篇关于UITableView框架更改动画问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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