gpt4 book ai didi

iphone - 动画表格 View 部分标题

转载 作者:行者123 更新时间:2023-11-28 18:44:28 25 4
gpt4 key购买 nike

我已经创建了这个 TableView 部分标题。它基本上是一个 UIView 容器,我在其中包装了该部分标题上的所有元素。

这个容器 View 由

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

一切正常。

现在我希望标题在表格出现时淡入。所以,我最初为容器声明 alpha = 0,然后在 viewDidAppear: 上执行此操作(啊,这个表在正在出现的 View Controller 中)。

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

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

}

没有任何反应,标题继续不可见。

我尝试添加:

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

提到的动画之前和之后,都没有成功。

在我看来,表头没有更新并且继续不可见。

最佳答案

首先,放一个NSLog在两个viewDidAppeartableView:viewForHeaderInSection:

你会看到 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 时调用动画即可。

关于iphone - 动画表格 View 部分标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6542876/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com