lukescott / DraggableCollectionView

Extension for the UICollectionView and UICollectionViewLayout that allows a user to move items with drag and drop. --- HELP WANTED --- Looking for maintainer and help with the experimental branch.
MIT License
549 stars 175 forks source link

Crash with two fingers & centroid issue #15

Open lukescott opened 11 years ago

lukescott commented 11 years ago

If you hold your finger on one cell, then place a finger on the other the center of the two fingers is used (different issue). When you lift the first finger it crashes with:

*\ Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'request for number of items before section 2147483647 when there are only 5 sections in the collection view'

I suspect it might have something to do with a numberOfItemsInSection call somewhere, but I'm going to have to do some more debugging to find out.

martijnpolak commented 11 years ago

Hi, I'm running into this issue and it looks like you can simply avoid it by setting maximumNumberOfTouches on _panPressGestureRecognizer to 1 in LSCollectionViewHelper::initWithCollectionView. You just have to define the property as a UIPanGestureRecognizer (instead of a UIGestureRecognizer) in the header file. Looking at the odd behaviour we get when using multi touch this might be the simplest solution, unless there's a benefit to having multi touch enabled?

gouravgupta72 commented 10 years ago

Hi, I'm using this on xcode-5, but not able to set maximumNumberOfTouches on _panPressGestureRecognizer to 1in LSCollectionViewHelper. I set multiple touch to no on my cell and collection view but still it causes crash.

Is there any other way to avoid this crash...? Thanks in advance.

chewedon commented 10 years ago

gouravgupta72,

I found out the problem why you can't set maximumNumberOfTouches.

In LSCollectionViewHelper's initWithCollectionView, you have this:

_panPressGestureRecognizer = [[UIPanGestureRecognizer alloc]
                                  initWithTarget:self action:@selector(handlePanGesture:)];
_panPressGestureRecognizer.delegate = self;

However, if you check the LSCollectionViewHelper.h file, you'll see panPressGestureRecognizer is declared as:

@property (nonatomic, readonly) UIGestureRecognizer *panPressGestureRecognizer;

I simply changed this to:

@property (nonatomic, readonly) UIPanGestureRecognizer *panPressGestureRecognizer;

Then I'm able to set:

_panPressGestureRecognizer.maximumNumberOfTouches = 1;

Not sure what effect this has on the draggable collection view library but it seems to fix the two finger crash for me too.

angelvasa commented 9 years ago

Just add below code snippet in LSCollectioViewHelper and you are done.

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
    if (gestureRecognizer.numberOfTouches < 1) {
        return YES;
    } else {
        return NO;
    }
}