From 5a51259149030bf4f22a2ed0dcaea65c4c294404 Mon Sep 17 00:00:00 2001 From: "logan.gauthier@metova.com" Date: Wed, 7 Oct 2015 16:16:25 -0500 Subject: [PATCH] Added customization points for configuring the appearance and animation of the dragging view. --- .../LXReorderableCollectionViewFlowLayout.h | 10 ++++++++++ .../LXReorderableCollectionViewFlowLayout.m | 18 ++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/LXReorderableCollectionViewFlowLayout/LXReorderableCollectionViewFlowLayout.h b/LXReorderableCollectionViewFlowLayout/LXReorderableCollectionViewFlowLayout.h index 76617f4..b545d26 100755 --- a/LXReorderableCollectionViewFlowLayout/LXReorderableCollectionViewFlowLayout.h +++ b/LXReorderableCollectionViewFlowLayout/LXReorderableCollectionViewFlowLayout.h @@ -34,8 +34,18 @@ @optional - (void)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout willBeginDraggingItemAtIndexPath:(NSIndexPath *)indexPath; +- (void)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout willBeginDraggingItemAtIndexPath:(NSIndexPath *)indexPath currentlyDraggedView:(UIView *)currentlyDraggedView; + +- (void)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout configureAnimationPropertiesForBeginningDrag:(UIView *)currentlyDraggedView; + - (void)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout didBeginDraggingItemAtIndexPath:(NSIndexPath *)indexPath; +- (void)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout didBeginDraggingItemAtIndexPath:(NSIndexPath *)indexPath currentlyDraggedView:(UIView *)currentlyDraggedView; + - (void)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout willEndDraggingItemAtIndexPath:(NSIndexPath *)indexPath; +- (void)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout willEndDraggingItemAtIndexPath:(NSIndexPath *)indexPath currentlyDraggedView:(UIView *)currentlyDraggedView; + +- (void)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout configureAnimationPropertiesForEndingDrag:(UIView *)currentlyDraggedView; + - (void)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout didEndDraggingItemAtIndexPath:(NSIndexPath *)indexPath; @end \ No newline at end of file diff --git a/LXReorderableCollectionViewFlowLayout/LXReorderableCollectionViewFlowLayout.m b/LXReorderableCollectionViewFlowLayout/LXReorderableCollectionViewFlowLayout.m index 9688aad..65b743d 100755 --- a/LXReorderableCollectionViewFlowLayout/LXReorderableCollectionViewFlowLayout.m +++ b/LXReorderableCollectionViewFlowLayout/LXReorderableCollectionViewFlowLayout.m @@ -331,6 +331,10 @@ - (void)handleLongPressGesture:(UILongPressGestureRecognizer *)gestureRecognizer self.currentViewCenter = self.currentView.center; + if ([self.delegate respondsToSelector:@selector(collectionView:layout:willBeginDraggingItemAtIndexPath:currentlyDraggedView:)]) { + [self.delegate collectionView:self.collectionView layout:self willBeginDraggingItemAtIndexPath:self.selectedItemIndexPath currentlyDraggedView:self.currentView]; + } + __weak typeof(self) weakSelf = self; [UIView animateWithDuration:0.3 @@ -342,6 +346,10 @@ - (void)handleLongPressGesture:(UILongPressGestureRecognizer *)gestureRecognizer strongSelf.currentView.transform = CGAffineTransformMakeScale(1.1f, 1.1f); highlightedImageView.alpha = 0.0f; imageView.alpha = 1.0f; + + if ([strongSelf.delegate respondsToSelector:@selector(collectionView:layout:configureAnimationPropertiesForBeginningDrag:)]) { + [strongSelf.delegate collectionView:strongSelf.collectionView layout:strongSelf configureAnimationPropertiesForBeginningDrag:strongSelf.currentView]; + } } } completion:^(BOOL finished) { @@ -352,6 +360,9 @@ - (void)handleLongPressGesture:(UILongPressGestureRecognizer *)gestureRecognizer if ([strongSelf.delegate respondsToSelector:@selector(collectionView:layout:didBeginDraggingItemAtIndexPath:)]) { [strongSelf.delegate collectionView:strongSelf.collectionView layout:strongSelf didBeginDraggingItemAtIndexPath:strongSelf.selectedItemIndexPath]; } + if ([strongSelf.delegate respondsToSelector:@selector(collectionView:layout:didBeginDraggingItemAtIndexPath:currentlyDraggedView:)]) { + [strongSelf.delegate collectionView:strongSelf.collectionView layout:strongSelf didBeginDraggingItemAtIndexPath:strongSelf.selectedItemIndexPath currentlyDraggedView:strongSelf.currentView]; + } } }]; @@ -365,6 +376,9 @@ - (void)handleLongPressGesture:(UILongPressGestureRecognizer *)gestureRecognizer if ([self.delegate respondsToSelector:@selector(collectionView:layout:willEndDraggingItemAtIndexPath:)]) { [self.delegate collectionView:self.collectionView layout:self willEndDraggingItemAtIndexPath:currentIndexPath]; } + if ([self.delegate respondsToSelector:@selector(collectionView:layout:willEndDraggingItemAtIndexPath:currentlyDraggedView:)]) { + [self.delegate collectionView:self.collectionView layout:self willEndDraggingItemAtIndexPath:currentIndexPath currentlyDraggedView:self.currentView]; + } self.selectedItemIndexPath = nil; self.currentViewCenter = CGPointZero; @@ -383,6 +397,10 @@ - (void)handleLongPressGesture:(UILongPressGestureRecognizer *)gestureRecognizer if (strongSelf) { strongSelf.currentView.transform = CGAffineTransformMakeScale(1.0f, 1.0f); strongSelf.currentView.center = layoutAttributes.center; + + if ([strongSelf.delegate respondsToSelector:@selector(collectionView:layout:configureAnimationPropertiesForEndingDrag:)]) { + [strongSelf.delegate collectionView:strongSelf.collectionView layout:strongSelf configureAnimationPropertiesForEndingDrag:strongSelf.currentView]; + } } } completion:^(BOOL finished) {