动画“tableHeaderView”中的动画“UITableView”标题

时间:2013-03-15 12:42:01

标签: iphone ios uitableview core-animation

对于“How to resize a tableHeaderView of a UITableView?”的答案,我在github上创建了一个小项目,该项目为UITableView添加了标题视图,并为新添加的标题视图和下方的单元格设置了动画它

然而,只要我添加标题单元格,我就会遇到令人讨厌的UI故障,因为标题不会与UITableView的单元格一起动画:

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

  1. 问题:最顶端的标题跳转到原始位置
  2. tableHeaderViewUITableViewCell一起动画到最终位置。
  3. 所以我的问题是,我如何确保标题也有效。

    你可以在这里看到效果,Section-1位于最终位置,而单元格和标题视图仍然是动画:

    header glitch

    这是我制作动画的方法:

    - (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];
        }
    }
    

1 个答案:

答案 0 :(得分:5)

这会修复它,但我不确定您是否需要此课程另一部分中的beginUpdatesendUpdates。因为在这个例子中你的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];
    }
}
相关问题