Bes*_*esi 3 iphone core-animation uitableview ios
对于" 如何调整UITableView的tableHeaderView? " 的答案,我在github上创建了一个小项目,它为a添加了一个标题视图,UITableView并为新添加的标题视图和它下面的单元格设置了动画.
但是,只要我添加标题单元格,就会出现令人讨厌的UI故障,因为标题不会与以下单元格一起生成动画UITableView:
当我添加标头时,会发生以下步骤:
tableHeaderView和UITableViewCell他们一起动画到他们的最终位置.所以我的问题是,我如何确保标题也有动画效果.
你可以在这里看到效果,Section-1它位于最终位置,而单元格和标题视图仍然是动画:

这是我做动画的方法:
- (void) showHeader:(BOOL)show animated:(BOOL)animated{
CGRect closedFrame = CGRectMake(0, 0, self.view.frame.size.width, 0);
CGRect newFrame = show?self.initialFrame:closedFrame;
if(animated){
// The UIView animation block handles the animation of our header view
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.3];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
// beginUpdates and endUpdates trigger the animation of our cells
[self.tableView beginUpdates];
}
self.headerView.frame = newFrame;
[self.tableView setTableHeaderView:self.headerView];
if(animated){
[self.tableView endUpdates];
[UIView commitAnimations];
}
}
Run Code Online (Sandbox Code Playgroud)
小智 6
这将修复它,但我不知道,如果你需要的beginUpdates,并endUpdates在这个类的另一部分.因为dataSource在这个例子中你并没有真正改变.
- (void)showHeader:(BOOL)show animated:(BOOL)animated {
CGRect closedFrame = CGRectMake(0, 0, self.view.frame.size.width, 0);
CGRect newFrame = show?self.initialFrame:closedFrame;
if(animated){
// The UIView animation block handles the animation of our header view
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.3];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
// beginUpdates and endUpdates trigger the animation of our cells
//[self.tableView beginUpdates];
}
self.headerView.frame = newFrame;
[self.tableView setTableHeaderView:self.headerView];
if(animated){
//[self.tableView endUpdates];
[UIView commitAnimations];
}
}
Run Code Online (Sandbox Code Playgroud)