Skip to content

Commit

Permalink
Gracefully cancel cell reordering when application will resign active…
Browse files Browse the repository at this point in the history
… notification sent
  • Loading branch information
sibljon committed Jun 16, 2013
1 parent d5bfb4d commit 308d1a3
Showing 1 changed file with 12 additions and 0 deletions.
Expand Up @@ -85,6 +85,9 @@ - (void)setupCollectionView {
action:@selector(handlePanGesture:)];
_panGestureRecognizer.delegate = self;
[self.collectionView addGestureRecognizer:_panGestureRecognizer];

// Useful in multiple scenarios: one common scenario being when the Notification Center drawer is pulled down
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleApplicationWillResignActive:) name: UIApplicationWillResignActiveNotification object:nil];
}

- (id)init {
Expand Down Expand Up @@ -303,6 +306,7 @@ - (void)handleLongPressGesture:(UILongPressGestureRecognizer *)gestureRecognizer

[self invalidateLayout];
} break;
case UIGestureRecognizerStateCancelled:
case UIGestureRecognizerStateEnded: {
NSIndexPath *currentIndexPath = self.selectedItemIndexPath;

Expand Down Expand Up @@ -381,6 +385,7 @@ - (void)handlePanGesture:(UIPanGestureRecognizer *)gestureRecognizer {
} break;
}
} break;
case UIGestureRecognizerStateCancelled:
case UIGestureRecognizerStateEnded: {
[self invalidatesScrollTimer];
} break;
Expand Down Expand Up @@ -457,6 +462,13 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(N
}
}

#pragma mark - Notifications

- (void)handleApplicationWillResignActive:(NSNotification *)notification {
self.panGestureRecognizer.enabled = NO;
self.panGestureRecognizer.enabled = YES;
}

#pragma mark - Depreciated methods

#pragma mark Starting from 0.1.0
Expand Down

0 comments on commit 308d1a3

Please sign in to comment.