Permalink
Browse files

Provides additional but optional delegate callback for will/did begin…

… reordering and will/did end reordering. There are runtime check for these optional delegate callback methods but from my opinion they are not in tight loop situation, so I find that there is nothing much to worry about.
  • Loading branch information...
1 parent 0bee595 commit 6cd339a62fef06b81399c3b689189116ff99360a @lxcid committed Oct 8, 2012
@@ -31,4 +31,11 @@
- (void)collectionView:(UICollectionView *)theCollectionView layout:(UICollectionViewLayout *)theLayout itemAtIndexPath:(NSIndexPath *)theFromIndexPath willMoveToIndexPath:(NSIndexPath *)theToIndexPath;
+@optional
+
+- (void)collectionView:(UICollectionView *)theCollectionView layout:(UICollectionViewLayout *)theLayout willBeginReorderingAtIndexPath:(NSIndexPath *)theIndexPath;
+- (void)collectionView:(UICollectionView *)theCollectionView layout:(UICollectionViewLayout *)theLayout didBeginReorderingAtIndexPath:(NSIndexPath *)theIndexPath;
+- (void)collectionView:(UICollectionView *)theCollectionView layout:(UICollectionViewLayout *)theLayout willEndReorderingAtIndexPath:(NSIndexPath *)theIndexPath;
+- (void)collectionView:(UICollectionView *)theCollectionView layout:(UICollectionViewLayout *)theLayout didEndReorderingAtIndexPath:(NSIndexPath *)theIndexPath;
+
@end
@@ -138,6 +138,13 @@ - (void)handleLongPressGesture:(UILongPressGestureRecognizer *)theLongPressGestu
CGPoint theLocationInCollectionView = [theLongPressGestureRecognizer locationInView:self.collectionView];
NSIndexPath *theIndexPathOfSelectedItem = [self.collectionView indexPathForItemAtPoint:theLocationInCollectionView];
+ if ([self.collectionView.delegate conformsToProtocol:@protocol(LXReorderableCollectionViewDelegateFlowLayout)]) {
+ id<LXReorderableCollectionViewDelegateFlowLayout> theDelegate = (id<LXReorderableCollectionViewDelegateFlowLayout>)self.collectionView.delegate;
+ if ([theDelegate respondsToSelector:@selector(collectionView:layout:willBeginReorderingAtIndexPath:)]) {
+ [theDelegate collectionView:self.collectionView layout:self willBeginReorderingAtIndexPath:theIndexPathOfSelectedItem];
+ }
+ }
+
UICollectionViewCell *theCollectionViewCell = [self.collectionView cellForItemAtIndexPath:theIndexPathOfSelectedItem];
theCollectionViewCell.highlighted = YES;
@@ -181,12 +188,27 @@ - (void)handleLongPressGesture:(UILongPressGestureRecognizer *)theLongPressGestu
}
completion:^(BOOL finished) {
[theHighlightedImageView removeFromSuperview];
+
+ if ([self.collectionView.delegate conformsToProtocol:@protocol(LXReorderableCollectionViewDelegateFlowLayout)]) {
+ id<LXReorderableCollectionViewDelegateFlowLayout> theDelegate = (id<LXReorderableCollectionViewDelegateFlowLayout>)self.collectionView.delegate;
+ if ([theDelegate respondsToSelector:@selector(collectionView:layout:didBeginReorderingAtIndexPath:)]) {
+ [theDelegate collectionView:self.collectionView layout:self didBeginReorderingAtIndexPath:theIndexPathOfSelectedItem];
+ }
+ }
}];
[self invalidateLayout];
} break;
case UIGestureRecognizerStateEnded: {
NSIndexPath *theIndexPathOfSelectedItem = self.selectedItemIndexPath;
+
+ if ([self.collectionView.delegate conformsToProtocol:@protocol(LXReorderableCollectionViewDelegateFlowLayout)]) {
+ id<LXReorderableCollectionViewDelegateFlowLayout> theDelegate = (id<LXReorderableCollectionViewDelegateFlowLayout>)self.collectionView.delegate;
+ if ([theDelegate respondsToSelector:@selector(collectionView:layout:willEndReorderingAtIndexPath:)]) {
+ [theDelegate collectionView:self.collectionView layout:self willEndReorderingAtIndexPath:theIndexPathOfSelectedItem];
+ }
+ }
+
self.selectedItemIndexPath = nil;
self.currentViewCenter = CGPointZero;
@@ -206,6 +228,13 @@ - (void)handleLongPressGesture:(UILongPressGestureRecognizer *)theLongPressGestu
[theStrongSelf.currentView removeFromSuperview];
[theStrongSelf invalidateLayout];
+
+ if ([self.collectionView.delegate conformsToProtocol:@protocol(LXReorderableCollectionViewDelegateFlowLayout)]) {
+ id<LXReorderableCollectionViewDelegateFlowLayout> theDelegate = (id<LXReorderableCollectionViewDelegateFlowLayout>)self.collectionView.delegate;
+ if ([theDelegate respondsToSelector:@selector(collectionView:layout:didEndReorderingAtIndexPath:)]) {
+ [theDelegate collectionView:self.collectionView layout:self didEndReorderingAtIndexPath:theIndexPathOfSelectedItem];
+ }
+ }
}];
} break;
default: {

0 comments on commit 6cd339a

Please sign in to comment.