【发布时间】:2016-10-13 02:52:16
【问题描述】:
我似乎找不到任何解决以下错误的方法。我在通常的 UIViewController 中使用集合视图,并使用新的 ios9 功能进行交互式重新排序。我还定义了我可以使用 targetIndexPathForMoveFromItemAtIndexPath: 移动选取的单元格的位置。
错误是当目标索引在collectionView 中不可见时,移动单元格会在原地保留其自身的副本,触摸结束的地方。 Please see bug scrren shot here。灰色单元格不允许放在粉色单元格之间,它应该放在最后一个灰色单元格之后,因为它在视图的开头,所以不可见。
我还使用摆动动画来重新排序,取自这篇文章。 https://littlebitesofcocoa.com/104-interactive-collection-view-re-ordering
如果您需要我定义手势识别器的代码,这里是
if (gesture.state==UIGestureRecognizerStateBegan){
NSIndexPath *selectedIndexPath = [self.collectionView indexPathForItemAtPoint:[gesture locationInView:self.collectionView]];
if(!selectedIndexPath)
return;
movingIndexPath=selectedIndexPath;
[self setEditing:YES];
[self.collectionView beginInteractiveMovementForItemAtIndexPath:selectedIndexPath];
TLTimelineCollectionCell *pickedCell=[self pickedUpCell];
movingCollectionCell=pickedCell;
[pickedCell stopWiggling];
[self animatePickingUpCell:pickedCell];
UICollectionViewLayoutAttributes *attributes = [self.collectionView layoutAttributesForItemAtIndexPath:selectedIndexPath];
CGRect cellRect = attributes.frame;
CGRect rect=[self.collectionView convertRect:cellRect toView:self.collectionView];
} else if (gesture.state==UIGestureRecognizerStateChanged) {
[self.collectionView updateInteractiveMovementTargetPosition:CGPointMake([gesture locationInView:gesture.view].x,39)];
} else {
if (gesture.state==UIGestureRecognizerStateEnded) {
[self.collectionView endInteractiveMovement];
} else {
[self.collectionView cancelInteractiveMovement];
}
[self animatePuttingDownCell:movingCollectionCell];
movingIndexPath=nil;
movingCollectionCell=nil;
[self setEditing:NO];
}
感谢任何帮助,谢谢!
更新
发现这个错误也发生在没有任何“摆动动画”的清晰项目中,只有一个集合视图控制器
【问题讨论】:
标签: ios objective-c uicollectionview