使用动画效果向右滑动时,将单元格移动到UITableView的底部(Moving cells to bottom of UITableView when swiped right with animation effect)

我正在尝试在UITableviewCells上实现滑动手势,因此当用户向右滑动时,我希望单元格移动到具有动画效果的表格底部( 就像iphone中的CLEAR应用程序一样 )。 我已将此链接称为http://www.cocoacontrols.com/platforms/ios/controls/jtgesturebasedtableviewdemo ,并尝试实施它。 下面是我的代码,我到目前为止,当状态是“正确的”

- (void)gestureRecognizer:(JTTableViewGestureRecognizer *)gestureRecognizer commitEditingState:(JTTableViewCellEditingState)state forRowAtIndexPath:(NSIndexPath *)indexPath { UITableView *tableView = gestureRecognizer.tableView; [tableView beginUpdates]; if (state == JTTableViewCellEditingStateLeft) { // An example to discard the cell at JTTableViewCellEditingStateLeft [self.rows removeObjectAtIndex:indexPath.row]; [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationLeft]; } else if (state == JTTableViewCellEditingStateRight) { ***NSString *selectedString = [self.rows objectAtIndex:indexPath.row]; [self.rows removeObjectAtIndex:indexPath.row]; //[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] // withRowAnimation:UITableViewRowAnimationLeft]; NSIndexPath *selectedIndexPath = [tableView indexPathForSelectedRow]; [tableView moveRowAtIndexPath:selectedIndexPath toIndexPath:[NSIndexPath indexPathForRow:[self.rows count]-1 inSection:0]]; [self.rows insertObject:selectedString atIndex:[self.rows count]]; [tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:0 inSection:0]] withRowAnimation:UITableViewRowAnimationBottom]; [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationLeft];*** } [tableView endUpdates]; // Row color needs update after datasource changes, reload it. [tableView performSelector:@selector(reloadVisibleRowsExceptIndexPath:) withObject:indexPath afterDelay:JTTableViewRowAnimationDuration]; }

因此,你可以看到状态是正确的,我正在尝试实现它,但我不知道如何获得动画效果。 所以朋友们,我请求通过这段代码帮助我。

关心Ranjit

I am trying to implement swipe gestures on the UITableviewCells, so when the user swipes to right I want the cell to move to the bottom of the table with animation effect (just like CLEAR app in iphone). I have referred this link http://www.cocoacontrols.com/platforms/ios/controls/jtgesturebasedtableviewdemo, and trying to implement it. below is my code which I have tried so far when the state is "right"

- (void)gestureRecognizer:(JTTableViewGestureRecognizer *)gestureRecognizer commitEditingState:(JTTableViewCellEditingState)state forRowAtIndexPath:(NSIndexPath *)indexPath { UITableView *tableView = gestureRecognizer.tableView; [tableView beginUpdates]; if (state == JTTableViewCellEditingStateLeft) { // An example to discard the cell at JTTableViewCellEditingStateLeft [self.rows removeObjectAtIndex:indexPath.row]; [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationLeft]; } else if (state == JTTableViewCellEditingStateRight) { ***NSString *selectedString = [self.rows objectAtIndex:indexPath.row]; [self.rows removeObjectAtIndex:indexPath.row]; //[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] // withRowAnimation:UITableViewRowAnimationLeft]; NSIndexPath *selectedIndexPath = [tableView indexPathForSelectedRow]; [tableView moveRowAtIndexPath:selectedIndexPath toIndexPath:[NSIndexPath indexPathForRow:[self.rows count]-1 inSection:0]]; [self.rows insertObject:selectedString atIndex:[self.rows count]]; [tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:0 inSection:0]] withRowAnimation:UITableViewRowAnimationBottom]; [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationLeft];*** } [tableView endUpdates]; // Row color needs update after datasource changes, reload it. [tableView performSelector:@selector(reloadVisibleRowsExceptIndexPath:) withObject:indexPath afterDelay:JTTableViewRowAnimationDuration]; }

So as you can see when the state is right I am trying to implement it but I am not understanding how to have a animation effect. So friends, I request to please go through this code and help me out.

Regards Ranjit

最满意答案

UITableView管理其单元格本身的布局。

你可以通过以下方式完成你想要的:

...明智地告诉表格视图不是受影响单元格的动画,创建复制视图层次结构并动画化这些视图,然后在最终状态显示表格。 - 要么 -

...子类化表视图并重新实现其动画逻辑。 - 要么 -

...创建自己的表格视图。

I worked on this and come with this solution, now I get the effect when I swipe the cell to the right and the cell moves to the bottom, but my cells are not updated , whenever I swipe cell to right,it takes the string of the cell which is at immediate below position of it . Not able to understand what I am missing

- (void)gestureRecognizer:(JTTableViewGestureRecognizer *)gestureRecognizer commitEditingState:(JTTableViewCellEditingState)state forRowAtIndexPath:(NSIndexPath *)indexPath { UITableView *tableView = gestureRecognizer.tableView; [tableView beginUpdates]; if (state == JTTableViewCellEditingStateRight) { NSIndexPath *selectedIndexPath = [tableView indexPathForSelectedRow]; [tableView moveRowAtIndexPath:selectedIndexPath toIndexPath:[NSIndexPath indexPathForRow:[self.rows count]-1 inSection:0]]; [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationLeft]; } [tableView endUpdates]; // Row color needs update after datasource changes, reload it. [tableView performSelector:@selector(reloadVisibleRowsExceptIndexPath:) withObject:indexPath afterDelay:JTTableViewRowAnimationDuration]; } -(void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath { NSString *selectedString = [self.rows objectAtIndex:sourceIndexPath.row]; [self.rows removeObjectAtIndex:sourceIndexPath.row]; [self.rows insertObject:selectedString atIndex:[self.rows count]-1]; }

更多推荐