[英]Animating a table view section header
我已经创建了这个表视图部分 header。 它基本上是一个UIView
容器,我在 header 部分包装了所有将 go 的元素。
此容器视图由
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
一切正常。
现在我希望 header 出现在淡入中,因为表格出现了。 因此,我最初为容器声明alpha = 0
,然后在viewDidAppear:
啊,此表位于正在出现的视图 controller 内)。
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[UIView animateWithDuration:1.0
animations:^{
[self.tableHeader setAlpha:1.0f];
}];
}
什么都没有发生,header 仍然不可见。
我试图添加:
[self.tableView beginUpdates]; //and
[self.tableView beginUpdates];
前后提到animation,都没有成功。
在我看来,表 header 没有更新并且继续不可见。
首先,在viewDidAppear
和tableView:viewForHeaderInSection:
上放置一个NSLog
:
你会看到viewDidAppear
首先执行,一旦 tableView 有一个异步加载并且你不知道什么时候会调用viewForHeaderInSection
。
一种解决方法如下:
-(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;
}
当表格返回 viewHeader 时,只需调用 animation。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.