11

我正在努力使用动画来动画删除 tableview 的页眉/页脚内容。我相信我可以在标题内容本身上调用 removeFromSuperview,或者只是将标题分配给 nil,但我不知道如何为它设置动画。一个简单的动画块不做任何事情 - 我如何淡入/淡出视图(在这种情况下为标签)?

4

7 回答 7

24

我写了一个如何使用动画块完全删除标题视图的示例。

[UIView beginAnimations:nil context:NULL];
[self.tableView setTableHeaderView:nil];
[UIView commitAnimations];

这当然假设这个动画是在你的 UITableViewController 类中被调用的。

简单地从超级视图中删除标题视图是行不通的,因为表格视图不知道调整自己的大小以填充以前的标题视图。标题视图的设置会导致表格视图自动刷新。

如果这不起作用,请检查 tableView 实例的分配。

于 2012-04-24T00:10:21.853 回答
10

我最终得到了以下简单的解决方案。它以动画方式删除标题。

[self.tableView beginUpdates];
self.tableView.tableHeaderView = nil;
[self.tableView endUpdates];

我意识到 WINSergey 的回复中提到了这一点,但我发现他的解释有点令人困惑。

于 2013-03-05T12:40:18.063 回答
1

我发现以下两个选项都可以正常工作:

选项1

[UIView animateWithDuration:0.15
                      delay:0.0
        options: UIViewAnimationCurveEaseOut
                 animations:^{deleteLabel.alpha = 0;}
             completion:nil];

选项 2

[UIView beginAnimations:nil context:nil];
deleteLabel.alpha = 0.0;
[UIView commitAnimations];
于 2012-04-24T01:43:03.393 回答
1

我有同样的问题,我想控制如何删除标题,这是我的方法:

在 ViewDidLoad :

UIView *transView = [[UIView alloc] initWithFrame:CGRectMake(0.f, 0.f, 320.f, 200.f)];
transView.backgroundColor = [UIColor clearColor];
self.headerView = transView;
[transView release];

[self.tableView setTableHeaderView:self.headerView];

然后当您需要删除标头时:

[UIView animateWithDuration:.3f
                      delay:.0f
                    options: UIViewAnimationOptionBeginFromCurrentState
                 animations:^{
                     self.headerView.frame = CGRectMake(0.0f, 0.0f, 320.f, 0.0f);
                 }
                 completion:^(BOOL finished) {
                       [tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForItem:0 inSection:section] atScrollPosition:UITableViewScrollPositionTop animated:YES];
                 }];
于 2013-05-14T09:48:15.357 回答
0

这是“按原样”完美地工作,我不关心动画

    [myPrettyViewControllerInstance letUpdatePrettyViewNow];
    [[self tableView] beginUpdates];
    [[self tableView] setTableHeaderView:[myPrettyViewControllerInstance view]];
    [[self tableView] endUpdates];

但如果我们不再需要它

    [[self tableView] setTableHeaderView:nil];

这就是我们所需要的,真的(如果它不是淡出 - 检查条件

    [[self tableView] setTableHeaderView:nil];

我们不需要

    [UIView beginAnimations:nil context:NULL];
    [[self tableView] setTableHeaderView:nil];
    [UIView commitAnimations];

    [[self tableView] beginUpdates];
    [[self tableView] setTableHeaderView:nil];
    [[self tableView] endUpdates];

    [[self tableView] setTableHeaderView:nil];
    [[self tableView] reloadData];

不..

于 2012-12-29T08:46:33.270 回答
0

我必须放 2 个动画才能让它工作。

 [UIView animateWithDuration:2.0f animations:^{
        mylbl.alpha = 0.1 ;
    } completion:^(BOOL finished) {
        [UIView animateWithDuration:2.0f animations:^{
            mylbl.alpha = 1.0 ;
        }];
    }];
于 2013-07-15T04:45:44.557 回答
0

如果有人这样做,我必须混合所有答案才能使其在UITableView. 只是做beginUpdatesendUpdates不是为我添加动画。这允许删除页脚,并且单元格通过动画很好地下降,而不是立即通过混蛋。

private func updateFooter(view : UIView?, size : CGFloat){

    UIView.beginAnimations(nil, context: nil)
    mainTableView.beginUpdates()
    mainTableView.tableFooterView = view
    mainTableView.tableFooterView?.frame.size.height = size
    mainTableView.endUpdates()
    UIView.commitAnimations()
}
于 2018-12-06T10:06:18.023 回答