【发布时间】:2014-06-13 18:37:51
【问题描述】:
所以我试图在添加和删除单元格的同时模拟折纸类型的折纸,就像 peek Calendar 应用程序:
通过继承 UITableView 并覆盖 insertRowsAtIndexPaths:withRowAnimation: 和 deleteRowsAtIndexPaths:withRowAnimation:,我已经非常接近这个功能了:
但是现在我似乎无法让动画看起来正确。下面是我当前的代码 - 我只是想帮助克服最后一个障碍(或者可能有一种完全不同的方法,例如将 tableview 添加到 tableviewcell)。
- (void)insertRowsAtIndexPaths:(NSArray *)indexPaths
withRowAnimation:(UITableViewRowAnimation)animation
{
[super insertRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationNone];
float duration = .30;
int i = 0;
for (NSIndexPath *indexPath in indexPaths) {
__block UITableViewCell *cell = [super cellForRowAtIndexPath:indexPath];
if (cell) { // If indexPath isn't visible we'll get nil here
//even cells flip up while odd cells flip down
if(i % 2 ==0){
cell.layer.anchorPoint = CGPointMake(.5, 0);
//start row off by rotating 90 degrees
__block CATransform3D t = CATransform3DIdentity;
t = CATransform3DTranslate(t, 0, -cell.bounds.size.height/2, 0);
t = CATransform3DRotate(t, hn_radians(90), 1, 0, 0);
t.m34 = -1.0/(cell.layer.bounds.size.height * 4.6666667);
cell.layer.transform = t;
//flip up
[UIView animateWithDuration:duration delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
t = CATransform3DIdentity;
t = CATransform3DTranslate(t, 0, -cell.bounds.size.height/2, 0);
cell.layer.transform = t;
NSLog(@"");
} completion:^(BOOL finished) {
cell.layer.transform = CATransform3DIdentity;
cell.layer.anchorPoint = CGPointMake(.5, .5);
}];
}
else{
cell.contentView.layer.anchorPoint = CGPointMake(.5, 1);
//start row off by rotating 90 degrees
__block CATransform3D t = CATransform3DIdentity;
t = CATransform3DTranslate(t, 0, -cell.contentView.bounds.size.height * 0.5f, 0);
t = CATransform3DRotate(t, hn_radians(-90), 1, 0, 0);
t.m34 = -1/500.f;
cell.contentView.layer.transform = t;
//flip down
[UIView animateWithDuration:duration delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
t = CATransform3DIdentity;
t = CATransform3DTranslate(t, 0, cell.contentView.bounds.size.height * 0.5f, 0);
cell.contentView.layer.transform = t;
} completion:^(BOOL finished) {
//reset anchor and transform
cell.contentView.layer.transform = CATransform3DIdentity;
cell.contentView.layer.anchorPoint = CGPointMake(.5, .5);
}];
}
i++;
}
}
}
【问题讨论】:
-
我已经检查了这个项目 - 没有做我想要的。它适用于从一个视图到另一个视图的单折叠过渡,但不适用于在 tableview 中添加/删除行,并且不支持多个折叠。
-
我想在 Android 中使用这个,有什么建议/链接吗?
-
@MweyaMutsvene 最后,你的效果编码成功了吗?有了 Trycatchfinally 的答案?
标签: ios uitableview ios7