From ee79b18275dd8b8430217934536a7794ad832617 Mon Sep 17 00:00:00 2001 From: Sxd Date: Wed, 6 Apr 2016 09:16:45 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=B8=AA=E5=B0=8Fbug=20xwp?= =?UTF-8?q?=5FmoveCell=E9=87=8C=E5=A4=B4=EF=BC=8C=E5=BA=94=E8=AF=A5?= =?UTF-8?q?=E5=88=A4=E6=96=AD=E4=B8=8B=5FmoveIndexPath=E4=B8=8D=E7=AD=89?= =?UTF-8?q?=E4=BA=8E=5ForiginalIndexPath=EF=BC=8C=E5=86=8D=E6=89=A7?= =?UTF-8?q?=E8=A1=8C=E4=BA=A4=E6=8D=A2=E4=BD=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Demo/PanCollectionView/ViewController.m | 2 +- .../XWDragCellCollectionView.m | 24 +++++++++++-------- 2 files changed, 15 insertions(+), 11 deletions(-) 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; } }