对于动画高度的UITableViewCell更改,恕不滚动 [英] Animate Height Change for UITableViewCell Without Scrolling

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

问题描述

我知道如何使用动画这里看到的方法,一个UITableViewCell的高度变化:<一href=\"http://stackoverflow.com/questions/460014/can-you-animate-a-height-change-on-a-uitableviewcell-when-selected\">Can选择当您在动画一个UITableViewCell的高度变化?

I know how to animate the height change of a UITableViewCell using the method seen here: Can you animate a height change on a UITableViewCell when selected?

但是,使用这种方法时,UITableView的滚动将在同一时间,我不希望它做的。

However, using that method, the UITableView will scroll at the same time, which I don't want it to do.

我有极少数细胞的UITableView;它占用小于屏幕高度。底电池具有的UITextField和,当它开始编辑,我手动设置内容的UITableView的偏移,使得与的UITextField该单元被滚动到顶部。然后,根据在的UITextField输入,我可能要增加的UITableViewCell的大小来显示额外的选项,或多或少

I have a UITableView with very few cells; it takes up less than the screen height. The bottom cell has a UITextField and, when it starts editing, I manually set the content offset of the UITableView so that the cell with the UITextField is scrolled to the top. Then, based on the input in the UITextField, I may want to increase the size of the UITableViewCell to show extra options, more or less.

的问题是,动画这种变化时,它会重新定位的UITableView使我的UITextField不再在顶部。

The problem is that, when animating this change, it will reposition the UITableView so that my UITextField is no longer at the top.

这是我在做什么,或多或少:

This is what I'm doing, more or less:

self.customAmountCellSize = height;

[self.tableView beginUpdates];
[self.tableView endUpdates];

我也试过

self.customAmountCellSize = height;
CGPoint originalOffset = self.tableView.contentOffset;

[self.tableView beginUpdates];
[self.tableView endUpdates];

[self.tableView setContentOffset:originalOffset animated:NO];

我要行高度动画​​,我不希望的UITableView滚动结果。

I want the row height animation, I do not want the UITableView to scroll as a result.

任何想法?

推荐答案

看来你遇到的问题是,你的表视图滚动过去的底部,所以当你更新的内容将尝试解决这个问题。

It appears the problem you're encountering is that your table view is scrolled past the bottom so when you update its content it will attempt to fix that.

有两种方法,你可以采取prevent滚动:

There are two approaches you could take to prevent scrolling:


  1. 设置表视图的内容插图是初始的白色空间的高度:

  1. Set the table view's content inset to be the height of the initial white space:

self.tableView.contentInset = UIEdgeInsetsMake(0, 0, verticalGap, 0);


  • ...添加空页脚视图具有相同的高度的垂直间距:

  • Add an empty footer view with the same height as the vertical gap:

    self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, verticalGap)];
    


  • 在这两种情况下,你需要计算你正在试图达到的垂直空间。然后,您需要恢复 contentInset tableFooterView 当你完成其原始状态。

    In both cases, you will need to calculate the vertical space you are trying to achieve. You then need to restore the contentInset or tableFooterView to its original state when you are done.

    这篇关于对于动画高度的UITableViewCell更改,恕不滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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