【发布时间】:2015-06-06 10:36:45
【问题描述】:
我有一个表格视图,其中包含在情节提要的 ViewController 场景中设计的原型单元格。
现在我的目标是当应用程序启动并加载视图时,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中逐行显示行或单元格,而不是一次动画?
任何信息或帮助将不胜感激。
谢谢。
【问题讨论】:
-
问题是什么?可能会更清楚
-
如何在UITableview中逐一显示行或单元格,而不是一次动画? @omerio
-
您可以增加 i 动画的延迟,例如第二个单元格为 2 秒,第三个单元格为 4 秒,以此类推,但正如您所见,这将花费很长时间,因此请确保您的用户不会在动画结束之前离开。
-
你找到合适的答案了吗?
标签: ios objective-c iphone uitableview animation