diff --git a/Demo/PanCollectionView/ViewController.m b/Demo/PanCollectionView/ViewController.m index 82128e0..a791c51 100644 --- a/Demo/PanCollectionView/ViewController.m +++ b/Demo/PanCollectionView/ViewController.m @@ -44,7 +44,7 @@ - (NSArray *)data{ NSArray *colors = @[[UIColor redColor], [UIColor blueColor], [UIColor yellowColor], [UIColor orangeColor], [UIColor greenColor]]; for (int i = 0; i < 5; i ++) { NSMutableArray *tempSection = @[].mutableCopy; - for (int j = 0; j < arc4random() % 6 + 5; j ++) { + for (int j = 0; j < arc4random() % 6 + 25; j ++) { NSString *str = [NSString stringWithFormat:@"%d--%d", i, j]; XWCellModel *model = [XWCellModel new]; model.backGroundColor = colors[i]; diff --git a/Demo/PanCollectionView/XWDragCellCollectionView.m b/Demo/PanCollectionView/XWDragCellCollectionView.m index 9946dc5..3a8058a 100644 --- a/Demo/PanCollectionView/XWDragCellCollectionView.m +++ b/Demo/PanCollectionView/XWDragCellCollectionView.m @@ -194,7 +194,7 @@ - (void)xwp_stopEdgeTimer{ - (void)xwp_moveCell{ for (UICollectionViewCell *cell in [self visibleCells]) { - if ([self indexPathForCell:cell] == _originalIndexPath) { + if ([self indexPathForCell:cell] == _originalIndexPath || cell.hidden == YES) { continue; } //计算中心距 @@ -202,16 +202,20 @@ - (void)xwp_moveCell{ CGFloat spacingY = fabs(_tempMoveCell.center.y - cell.center.y); if (spacingX <= _tempMoveCell.bounds.size.width / 2.0f && spacingY <= _tempMoveCell.bounds.size.height / 2.0f) { _moveIndexPath = [self indexPathForCell:cell]; - //更新数据源 - [self xwp_updateDataSource]; - //移动 - [self moveItemAtIndexPath:_originalIndexPath toIndexPath:_moveIndexPath]; - //通知代理 - if ([self.delegate respondsToSelector:@selector(dragCellCollectionView:moveCellFromIndexPath:toIndexPath:)]) { - [self.delegate dragCellCollectionView:self moveCellFromIndexPath:_originalIndexPath toIndexPath:_moveIndexPath]; + + if (![_moveIndexPath isEqual:_originalIndexPath]) + { + //更新数据源 + [self xwp_updateDataSource]; + //移动 + [self moveItemAtIndexPath:_originalIndexPath toIndexPath:_moveIndexPath]; + //通知代理 + if ([self.delegate respondsToSelector:@selector(dragCellCollectionView:moveCellFromIndexPath:toIndexPath:)]) { + [self.delegate dragCellCollectionView:self moveCellFromIndexPath:_originalIndexPath toIndexPath:_moveIndexPath]; + } + //设置移动后的起始indexPath + _originalIndexPath = _moveIndexPath; } - //设置移动后的起始indexPath - _originalIndexPath = _moveIndexPath; break; } }