Skip to content

Commit 308d1a3

Browse files
committed
Gracefully cancel cell reordering when application will resign active notification sent
1 parent d5bfb4d commit 308d1a3

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

LXReorderableCollectionViewFlowLayout/LXReorderableCollectionViewFlowLayout.m

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ - (void)setupCollectionView {
8585
action:@selector(handlePanGesture:)];
8686
_panGestureRecognizer.delegate = self;
8787
[self.collectionView addGestureRecognizer:_panGestureRecognizer];
88+
89+
// Useful in multiple scenarios: one common scenario being when the Notification Center drawer is pulled down
90+
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleApplicationWillResignActive:) name: UIApplicationWillResignActiveNotification object:nil];
8891
}
8992

9093
- (id)init {
@@ -303,6 +306,7 @@ - (void)handleLongPressGesture:(UILongPressGestureRecognizer *)gestureRecognizer
303306

304307
[self invalidateLayout];
305308
} break;
309+
case UIGestureRecognizerStateCancelled:
306310
case UIGestureRecognizerStateEnded: {
307311
NSIndexPath *currentIndexPath = self.selectedItemIndexPath;
308312

@@ -381,6 +385,7 @@ - (void)handlePanGesture:(UIPanGestureRecognizer *)gestureRecognizer {
381385
} break;
382386
}
383387
} break;
388+
case UIGestureRecognizerStateCancelled:
384389
case UIGestureRecognizerStateEnded: {
385390
[self invalidatesScrollTimer];
386391
} break;
@@ -457,6 +462,13 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(N
457462
}
458463
}
459464

465+
#pragma mark - Notifications
466+
467+
- (void)handleApplicationWillResignActive:(NSNotification *)notification {
468+
self.panGestureRecognizer.enabled = NO;
469+
self.panGestureRecognizer.enabled = YES;
470+
}
471+
460472
#pragma mark - Depreciated methods
461473

462474
#pragma mark Starting from 0.1.0

0 commit comments

Comments
 (0)