动画"tableHeaderView"中的动画"UITableView"标题

Bes*_*esi 3 iphone core-animation uitableview ios

对于" 如何调整UITableView的tableHeaderView? " 的答案,我在github上创建了一个小项目,它为a添加了一个标题视图,UITableView并为新添加的标题视图和它下面的单元格设置了动画.

但是,只要我添加标题单元格,就会出现令人讨厌的UI故障,因为标题不会与以下单元格一起生成动画UITableView:

当我添加标头时,会发生以下步骤:

  1. 问题:最顶部的标题跳转到原始位置
  2. tableHeaderViewUITableViewCell他们一起动画到他们的最终位置.

所以我的问题是,我如何确保标题也有动画效果.

你可以在这里看到效果,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)

  • 这对我不起作用....它会激活表视图,但标题只显示在顶部.我在自定义表头视图上使用布局约束,如果这可能会影响任何东西. (2认同)