我期望能夠在保持當前位置的同時展開/收縮UITableView中的所有單元格,並使變化爲高度變化設置動畫。本質上,它應該看起來像當前正在查看的單元格正在展開/收縮,並且滾動位置保持不變。在保持滾動位置的同時動態調整所有UITableViewCell的高度
我能夠擴大/由具有不同高度2點的狀態,並呼籲
[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationAutomatic];
聯繫細胞和我試着做,以保持相同的位置(不是100%這個計算是正確的):
//calculate the new position it should scroll to based on new cell height
CGFloat posFromTop = self.tableView.contentOffset.y;
CGFloat newDistance = 0;
if(expandedState)
{
CGFloat cellsFromTop = posFromTop/kExpandedCellHeight;
newDistance = cellsFromTop * kCollapsedCellHeight;
}
else
{
CGFloat cellsFromTop = posFromTop/kMGLCollapsedCellHeight;
newDistance = cellsFromTop * kMGLExpandedCellHeight;
}
}
//reload section
[self.tableView setContentOffset:CGPointMake(0, newDistance) animated:YES];
[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationAutomatic];
雖然這似乎是一種工作,它不保存位置,因爲它動畫,閃白,所以它的震盪並不會看起來像的tableView被重新加載期間繼續留。
任何人都有一種方法,可以在保持相同位置的同時平滑動畫所有單元格的高度?
您是否找到解決方案? – sim