objective-c – 是否可以在使用UICollectionViewFlowLayout的UIC
说我有一个UICollectionView使用UICollectionViewFlowLayout和以下格式:
1 2 3 4 5 6 7 8 9 我触摸单元格9并将其拖动到单元格6上,将单元格9移动到单元格6的单元格和单元格6到单元格9的位置: 1 2 3 4 5 9 7 8 6 有没有办法轻松移动和动画单元格6到单元格9以及移动和动画单元格9到单元格6的位置?还是我必须将UICollectionViewLayout子类化?如果我必须对UICollectionViewLayout进行子类化,那该怎么做?我已经尝试明确设置单元格的中心 – (UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath 但没有成功. 解决方法
经过很多的敲击,我发现的解决方案是使用moveItemAtIndexPath:toIndexPath里面的performBatchUpdates:completion.根据
documentation for performBatchUpdates:完成:
所以,我本来做的是什么 [self performBatchUpdates:^{ [self moveItemAtIndexPath:fromIp toIndexPath:toIp]; [self moveItemAtIndexPath:toIp toIndexPath:fromIp]; } completion:^(BOOL finished) { // update data source here // e.g [dataSource exchangeObjectAtIndex:fromIp.row withObjectAtIndex:toIp.row]; }]; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |