开发者

Animating a table view section header

I have created this table view section header. It is basical开发者_开发问答ly a UIView container where I wrapped all elements that will go on that section header.

This container view is returned by

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section 

and everything is working fine.

Now I want the header to appear in fade in, as the table appears. So, I initially declare alpha = 0 for the container and then do this on viewDidAppear: (ah, this table is inside a view controller that is appearing).

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];

    [UIView animateWithDuration:1.0
         animations:^{
             [self.tableHeader setAlpha:1.0f];
     }];

}

Nothing happens and the header continues to be invisible.

I have tried to add:

[self.tableView beginUpdates]; //and
[self.tableView beginUpdates];

before and after the mentioned animation, without success.

It appears to me that the table header is not updating and continues to be invisible.


First, put a NSLog on both viewDidAppear and tableView:viewForHeaderInSection:

You gonna see that the viewDidAppear executes first, once tableView has an asynchronous loading and you don't know when will call the viewForHeaderInSection.

One workaround is the following:

-(UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {

    _tableHeader = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 100)];
    _tableHeader.backgroundColor = [UIColor redColor];
    _tableHeader.alpha = 0;

    [UIView animateWithDuration:1.0
                 animations:^{
                     [_tableHeader setAlpha:1.0f];
                 }];

    return _tableHeader;

}

Just call the animation when the table will return the viewHeader.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜