Programmaticlaly moving rows with animation in UIT

2019-01-31 09:17发布

I want to move a row to the bottom of my UITableView with cool animation effect just like in this Grocery Shopping List app.

Just like we can move rows with reordering control like:

reordering uitableview rows programmatically

How can I create such animation?

3条回答
Root(大扎)
2楼-- · 2019-01-31 09:44

This is kind of similar to what I have done to allow drag and drop from one scrollview to another.

You will want to create a duplicate/dummy cell (for visual effect), then remove the original cell, then animate the duplicate, then insert into the bottom and then finally remove the duplicate/dummy cell.

查看更多
爱情/是我丢掉的垃圾
3楼-- · 2019-01-31 09:52

Important: This answer assumes iPhone OS 3.x. See the answer above for iOS 5.x

I don't know what is the "cool animation effect just like in Grocery Shopping List app". Not everyone has that app.


Rows cannot be moved programmatically.

However, you can simultaneously insert and delete a row to simulate a move.

[tableView beginUpdates];
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:rowToMove]
                 withRowAnimation:UITableViewRowAnimationLeft];
[tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:indexPathToMoveTo]
                 withRowAnimation:UITableViewRowAnimationLeft];
// update your dataSource as well.
[tableView endUpdates];
查看更多
看我几分像从前
4楼-- · 2019-01-31 09:54

In IOS 5 this can be done with the following UITableView selector:

- (void)moveRowAtIndexPath:(NSIndexPath *)indexPath toIndexPath:(NSIndexPath *)newIndexPath

For example:

[self.tableView moveRowAtIndexPath:indexPath toIndexPath:[NSIndexPath indexPathForRow:[items count] - 1 inSection:1]];
查看更多
登录 后发表回答