edc*_*591 3 cocoa-touch core-animation objective-c uitableview ios
我的目标是UITableViewCell在屏幕的一侧(例如在Twitter中)滑动,然后从另一侧滑回.我能够让细胞从屏幕向右滑动,但我似乎无法弄清楚如何让它从左后方滑回到屏幕上.这是我的代码,将其向右滑动:
UITableViewCell *cell = [self cellForRowAtIndexPath:indexPath];
[cell.layer setAnchorPoint:CGPointMake(0, 0.5)];
[cell.layer setPosition:CGPointMake(cell.frame.size.width, cell.layer.position.y)];
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position.x"];
[animation setRemovedOnCompletion:NO];
[animation setDelegate:self];
[animation setDuration:0.14];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear]];
[cell.layer addAnimation:animation forKey:@"reveal"];
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助!
UITableView提供了使用动画插入和删除行的方法,并为您处理所有动画.尝试这样的事情:
[tableView beginUpdates];
[tableView deleteRowsAtIndexPaths:myIndexPaths
withRowAnimation:UITableViewCellRowAnimationRight];
[tableView endUpdates];
Run Code Online (Sandbox Code Playgroud)
然后在新单元格中滑动:
[tableView beginUpdates];
[tableView insertRowsAtIndexPaths:myNewIndexPaths
withRowAnimation:UITableViewCellRowAnimationLeft];
[tableView endUpdates];
Run Code Online (Sandbox Code Playgroud)
这些beginUpdates/endUpdates方法会导致动画被批量处理并立即执行.
小心两件事:
对于大量的表数据,插入可能需要很长时间(特别是如果您基本上替换整个表).[tableView reloadData]在这种情况下,调用效果更好,但deleteRowsAtIndexPath:withRowAnimation:仍可用于获得良好的视觉效果.
您必须确保支持表的实际数据相应且正确地更改.也就是说,如果要从表中删除或插入行,那么为表提供的数组(或其他任何内容)也必须正确反映每一步中表中的行数.
| 归档时间: |
|
| 查看次数: |
3490 次 |
| 最近记录: |