Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修复个小bug #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Demo/PanCollectionView/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
24 changes: 14 additions & 10 deletions Demo/PanCollectionView/XWDragCellCollectionView.m
Original file line number Diff line number Diff line change
Expand Up @@ -194,24 +194,28 @@ - (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;
}
//计算中心距
CGFloat spacingX = fabs(_tempMoveCell.center.x - cell.center.x);
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;
}
}
Expand Down