gpt4 book ai didi

ios - 用动画在 UITableview 中一一显示行/单元格

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

我有一个 TableView ,其中包含在 Storyboard的 ViewController 场景中设计的原型(prototype)单元格。

现在我的目标是当应用程序启动并加载 View 时,tableview 中的数据不应立即出现,而是会通过动画一个接一个地出现。

这是我制作动画的代码:-

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (![shownIndexes containsObject:indexPath]) {
[shownIndexes addObject:indexPath];
[UIView animateWithDuration:2.0f delay:0.0f usingSpringWithDamping:0.5f initialSpringVelocity:1.0f options:UIViewAnimationOptionAllowAnimatedContent animations:^{
vw.frame = frame;
} completion:^(BOOL finished) {

}];
}

其他方法:-

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
tableView.separatorStyle = UITableViewCellSeparatorStyleNone;

return 1; //count of section
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

return 20; //count number of row from counting array hear cataGorry is An Array
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 120;

}

- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *MyIdentifier = @"CellA";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;


}

下面的代码是对最初显示在 tableview 中的前 5 个单元格进行动画处理,但之后当我滚动时它会一个接一个地发生。

所以主要问题是

UITableview 中的行或单元格如何用动画不是一次显示一个一个显示?

任何信息或帮助将不胜感激。

谢谢。

最佳答案

首先告诉表格,in 只有一行,in numberOfRows...。延迟后,返回 2 而不是 1。依此类推。

关于ios - 用动画在 UITableview 中一一显示行/单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30681811/

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