From e740a3c65eabcb7333491ccd191944d494d9bd34 Mon Sep 17 00:00:00 2001 From: Stan Chang Khin Boon Date: Tue, 2 Apr 2013 00:08:44 +0800 Subject: [PATCH 01/13] - Fixed a mistake with naming LXReorderableCollectionViewDataSource without capitalising the source. --- .../LXCollectionViewController.h | 2 +- .../LXCollectionViewController.m | 2 +- .../LXReorderableCollectionViewFlowLayout.h | 2 +- .../LXReorderableCollectionViewFlowLayout.m | 6 +++--- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/LXRCVFL Example using Storyboard/LXRCVFL Example using Storyboard/LXCollectionViewController.h b/LXRCVFL Example using Storyboard/LXRCVFL Example using Storyboard/LXCollectionViewController.h index c39915b..6657ba1 100644 --- a/LXRCVFL Example using Storyboard/LXRCVFL Example using Storyboard/LXCollectionViewController.h +++ b/LXRCVFL Example using Storyboard/LXRCVFL Example using Storyboard/LXCollectionViewController.h @@ -9,7 +9,7 @@ #import #import "LXReorderableCollectionViewFlowLayout.h" -@interface LXCollectionViewController : UICollectionViewController +@interface LXCollectionViewController : UICollectionViewController @property (strong, nonatomic) NSMutableArray *deck; diff --git a/LXRCVFL Example using Storyboard/LXRCVFL Example using Storyboard/LXCollectionViewController.m b/LXRCVFL Example using Storyboard/LXRCVFL Example using Storyboard/LXCollectionViewController.m index afef591..a899026 100644 --- a/LXRCVFL Example using Storyboard/LXRCVFL Example using Storyboard/LXCollectionViewController.m +++ b/LXRCVFL Example using Storyboard/LXRCVFL Example using Storyboard/LXCollectionViewController.m @@ -78,7 +78,7 @@ - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cell return playingCardCell; } -#pragma mark - LXReorderableCollectionViewDatasource methods +#pragma mark - LXReorderableCollectionViewDataSource methods - (void)collectionView:(UICollectionView *)collectionView itemAtIndexPath:(NSIndexPath *)fromIndexPath willMoveToIndexPath:(NSIndexPath *)toIndexPath { PlayingCard *playingCard = [self.deck objectAtIndex:fromIndexPath.item]; diff --git a/LXReorderableCollectionViewFlowLayout/LXReorderableCollectionViewFlowLayout.h b/LXReorderableCollectionViewFlowLayout/LXReorderableCollectionViewFlowLayout.h index e54ce58..ed0884e 100755 --- a/LXReorderableCollectionViewFlowLayout/LXReorderableCollectionViewFlowLayout.h +++ b/LXReorderableCollectionViewFlowLayout/LXReorderableCollectionViewFlowLayout.h @@ -18,7 +18,7 @@ @end -@protocol LXReorderableCollectionViewDatasource +@protocol LXReorderableCollectionViewDataSource - (void)collectionView:(UICollectionView *)collectionView itemAtIndexPath:(NSIndexPath *)fromIndexPath willMoveToIndexPath:(NSIndexPath *)toIndexPath; diff --git a/LXReorderableCollectionViewFlowLayout/LXReorderableCollectionViewFlowLayout.m b/LXReorderableCollectionViewFlowLayout/LXReorderableCollectionViewFlowLayout.m index 07a1235..4101b49 100755 --- a/LXReorderableCollectionViewFlowLayout/LXReorderableCollectionViewFlowLayout.m +++ b/LXReorderableCollectionViewFlowLayout/LXReorderableCollectionViewFlowLayout.m @@ -54,7 +54,7 @@ @interface LXReorderableCollectionViewFlowLayout () @property (assign, nonatomic) CGPoint panTranslationInCollectionView; @property (strong, nonatomic) NSTimer *scrollingTimer; -@property (assign, nonatomic, readonly) id dataSource; +@property (assign, nonatomic, readonly) id dataSource; @property (assign, nonatomic, readonly) id delegate; @end @@ -117,8 +117,8 @@ - (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttribut } } -- (id)dataSource { - return (id)self.collectionView.dataSource; +- (id)dataSource { + return (id)self.collectionView.dataSource; } - (id)delegate { From 75601c7c7b94df8cd31a7cfa98bff3ca2ec8f2b7 Mon Sep 17 00:00:00 2001 From: Stan Chang Khin Boon Date: Tue, 2 Apr 2013 00:28:56 +0800 Subject: [PATCH 02/13] - Reverts to sharing ownership of gesture recognizers between collection view and layout. --- .../LXReorderableCollectionViewFlowLayout.h | 4 ++-- .../LXReorderableCollectionViewFlowLayout.m | 20 +++++++++---------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/LXReorderableCollectionViewFlowLayout/LXReorderableCollectionViewFlowLayout.h b/LXReorderableCollectionViewFlowLayout/LXReorderableCollectionViewFlowLayout.h index ed0884e..25500d3 100755 --- a/LXReorderableCollectionViewFlowLayout/LXReorderableCollectionViewFlowLayout.h +++ b/LXReorderableCollectionViewFlowLayout/LXReorderableCollectionViewFlowLayout.h @@ -11,8 +11,8 @@ @property (assign, nonatomic) CGFloat scrollingSpeed; @property (assign, nonatomic) UIEdgeInsets scrollingTriggerEdgeInsets; -@property (weak, nonatomic, readonly) UILongPressGestureRecognizer *longPressGestureRecognizer; -@property (weak, nonatomic, readonly) UIPanGestureRecognizer *panGestureRecognizer; +@property (strong, nonatomic, readonly) UILongPressGestureRecognizer *longPressGestureRecognizer; +@property (strong, nonatomic, readonly) UIPanGestureRecognizer *panGestureRecognizer; - (void)setUpGestureRecognizersOnCollectionView __attribute__((deprecated("Calls to setUpGestureRecognizersOnCollectionView method are not longer needed as setup are done automatically through KVO."))); diff --git a/LXReorderableCollectionViewFlowLayout/LXReorderableCollectionViewFlowLayout.m b/LXReorderableCollectionViewFlowLayout/LXReorderableCollectionViewFlowLayout.m index 4101b49..881847e 100755 --- a/LXReorderableCollectionViewFlowLayout/LXReorderableCollectionViewFlowLayout.m +++ b/LXReorderableCollectionViewFlowLayout/LXReorderableCollectionViewFlowLayout.m @@ -67,25 +67,23 @@ - (void)setDefaults { } - (void)setupCollectionView { - UILongPressGestureRecognizer *longPressGestureRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self - action:@selector(handleLongPressGesture:)]; - longPressGestureRecognizer.delegate = self; - [self.collectionView addGestureRecognizer:longPressGestureRecognizer]; + _longPressGestureRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self + action:@selector(handleLongPressGesture:)]; + _longPressGestureRecognizer.delegate = self; + [self.collectionView addGestureRecognizer:_longPressGestureRecognizer]; // Links the default long press gesture recognizer to the custom long press gesture recognizer we are creating now // by enforcing failure dependency so that they doesn't clash. for (UIGestureRecognizer *gestureRecognizer in self.collectionView.gestureRecognizers) { if ([gestureRecognizer isKindOfClass:[UILongPressGestureRecognizer class]]) { - [gestureRecognizer requireGestureRecognizerToFail:longPressGestureRecognizer]; + [gestureRecognizer requireGestureRecognizerToFail:_longPressGestureRecognizer]; } } - _longPressGestureRecognizer = longPressGestureRecognizer; - UIPanGestureRecognizer *panGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self - action:@selector(handlePanGesture:)]; - panGestureRecognizer.delegate = self; - [self.collectionView addGestureRecognizer:panGestureRecognizer]; - _panGestureRecognizer = panGestureRecognizer; + _panGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self + action:@selector(handlePanGesture:)]; + _panGestureRecognizer.delegate = self; + [self.collectionView addGestureRecognizer:_panGestureRecognizer]; } - (id)init { From 5907db5ea1498a7183a931e7c6364262f9777966 Mon Sep 17 00:00:00 2001 From: Jonathan Hersh Date: Tue, 9 Apr 2013 15:19:35 -0700 Subject: [PATCH 03/13] Fix ordering of adding long press gesture recognizer. --- .../LXReorderableCollectionViewFlowLayout.m | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/LXReorderableCollectionViewFlowLayout/LXReorderableCollectionViewFlowLayout.m b/LXReorderableCollectionViewFlowLayout/LXReorderableCollectionViewFlowLayout.m index 881847e..772ecd0 100755 --- a/LXReorderableCollectionViewFlowLayout/LXReorderableCollectionViewFlowLayout.m +++ b/LXReorderableCollectionViewFlowLayout/LXReorderableCollectionViewFlowLayout.m @@ -70,7 +70,6 @@ - (void)setupCollectionView { _longPressGestureRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPressGesture:)]; _longPressGestureRecognizer.delegate = self; - [self.collectionView addGestureRecognizer:_longPressGestureRecognizer]; // Links the default long press gesture recognizer to the custom long press gesture recognizer we are creating now // by enforcing failure dependency so that they doesn't clash. @@ -80,6 +79,8 @@ - (void)setupCollectionView { } } + [self.collectionView addGestureRecognizer:_longPressGestureRecognizer]; + _panGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePanGesture:)]; _panGestureRecognizer.delegate = self; From 65833b63003742a14bb5d4ab3015984919e2eb66 Mon Sep 17 00:00:00 2001 From: Stan Chang Khin Boon Date: Fri, 3 May 2013 02:02:17 +0800 Subject: [PATCH 04/13] - Link to master. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5ab50ef..ad768c5 100644 --- a/README.md +++ b/README.md @@ -65,4 +65,4 @@ Credits License ======= -LXReorderableCollectionViewFlowLayout is available under the MIT license. +LXReorderableCollectionViewFlowLayout is available under [the MIT license](blob/master/LICENSE). From d5bfb4db82124cfed96caa5846e56907dff7ff7f Mon Sep 17 00:00:00 2001 From: Stan Chang Khin Boon Date: Fri, 3 May 2013 02:03:46 +0800 Subject: [PATCH 05/13] - Apparently, Github is smarter than I thought. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ad768c5..fd65fc5 100644 --- a/README.md +++ b/README.md @@ -65,4 +65,4 @@ Credits License ======= -LXReorderableCollectionViewFlowLayout is available under [the MIT license](blob/master/LICENSE). +LXReorderableCollectionViewFlowLayout is available under [the MIT license](LICENSE). From 96571cbc74091e416ec3249f58f82afc2dbc6b0f Mon Sep 17 00:00:00 2001 From: Zach Drayer Date: Sun, 5 May 2013 10:21:26 -0700 Subject: [PATCH 06/13] Use CADisplayLink instead of NSTimer to know when to redraw on scroll. --- .../project.pbxproj | 4 ++ .../LXReorderableCollectionViewFlowLayout.m | 44 ++++++++++++------- 2 files changed, 33 insertions(+), 15 deletions(-) diff --git a/LXRCVFL Example using Storyboard/LXRCVFL Example using Storyboard.xcodeproj/project.pbxproj b/LXRCVFL Example using Storyboard/LXRCVFL Example using Storyboard.xcodeproj/project.pbxproj index 485eb33..f9bd4ed 100644 --- a/LXRCVFL Example using Storyboard/LXRCVFL Example using Storyboard.xcodeproj/project.pbxproj +++ b/LXRCVFL Example using Storyboard/LXRCVFL Example using Storyboard.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 927A97F41736CA0E00539F5E /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 927A97F31736CA0E00539F5E /* QuartzCore.framework */; }; AB0E97C7161B4BEC005498A0 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AB0E97C6161B4BEC005498A0 /* UIKit.framework */; }; AB0E97C9161B4BEC005498A0 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AB0E97C8161B4BEC005498A0 /* Foundation.framework */; }; AB0E97CB161B4BEC005498A0 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AB0E97CA161B4BEC005498A0 /* CoreGraphics.framework */; }; @@ -25,6 +26,7 @@ /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 927A97F31736CA0E00539F5E /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; }; AB0E97C2161B4BEC005498A0 /* LXRCVFL Example using Storyboard.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "LXRCVFL Example using Storyboard.app"; sourceTree = BUILT_PRODUCTS_DIR; }; AB0E97C6161B4BEC005498A0 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; }; AB0E97C8161B4BEC005498A0 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; @@ -55,6 +57,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 927A97F41736CA0E00539F5E /* QuartzCore.framework in Frameworks */, AB0E97C7161B4BEC005498A0 /* UIKit.framework in Frameworks */, AB0E97C9161B4BEC005498A0 /* Foundation.framework in Frameworks */, AB0E97CB161B4BEC005498A0 /* CoreGraphics.framework in Frameworks */, @@ -86,6 +89,7 @@ AB0E97C5161B4BEC005498A0 /* Frameworks */ = { isa = PBXGroup; children = ( + 927A97F31736CA0E00539F5E /* QuartzCore.framework */, AB0E97C6161B4BEC005498A0 /* UIKit.framework */, AB0E97C8161B4BEC005498A0 /* Foundation.framework */, AB0E97CA161B4BEC005498A0 /* CoreGraphics.framework */, diff --git a/LXReorderableCollectionViewFlowLayout/LXReorderableCollectionViewFlowLayout.m b/LXReorderableCollectionViewFlowLayout/LXReorderableCollectionViewFlowLayout.m index 772ecd0..1ec84fd 100755 --- a/LXReorderableCollectionViewFlowLayout/LXReorderableCollectionViewFlowLayout.m +++ b/LXReorderableCollectionViewFlowLayout/LXReorderableCollectionViewFlowLayout.m @@ -7,6 +7,7 @@ #import "LXReorderableCollectionViewFlowLayout.h" #import +#import #define LX_FRAMES_PER_SECOND 60.0 @@ -28,6 +29,20 @@ typedef NS_ENUM(NSInteger, LXScrollingDirection) { static NSString * const kLXScrollingDirectionKey = @"LXScrollingDirection"; static NSString * const kLXCollectionViewKeyPath = @"collectionView"; +@interface CADisplayLink (LX_userInfo) +@property (nonatomic, copy) NSDictionary *LX_userInfo; +@end + +@implementation CADisplayLink (LX_userInfo) +- (void) setLX_userInfo:(NSDictionary *) LX_userInfo { + objc_setAssociatedObject(self, "LX_userInfo", LX_userInfo, OBJC_ASSOCIATION_COPY); +} + +- (NSDictionary *) LX_userInfo { + return objc_getAssociatedObject(self, "LX_userInfo"); +} +@end + @interface UICollectionViewCell (LXReorderableCollectionViewFlowLayout) - (UIImage *)LX_rasterizedImage; @@ -52,7 +67,7 @@ @interface LXReorderableCollectionViewFlowLayout () @property (strong, nonatomic) UIView *currentView; @property (assign, nonatomic) CGPoint currentViewCenter; @property (assign, nonatomic) CGPoint panTranslationInCollectionView; -@property (strong, nonatomic) NSTimer *scrollingTimer; +@property (strong, nonatomic) CADisplayLink *displayLink; @property (assign, nonatomic, readonly) id dataSource; @property (assign, nonatomic, readonly) id delegate; @@ -152,35 +167,34 @@ - (void)invalidateLayoutIfNecessary { } - (void)invalidatesScrollTimer { - if (self.scrollingTimer.isValid) { - [self.scrollingTimer invalidate]; + if (!self.displayLink.paused) { + [self.displayLink invalidate]; } - self.scrollingTimer = nil; + self.displayLink = nil; } - (void)setupScrollTimerInDirection:(LXScrollingDirection)direction { - if (self.scrollingTimer.isValid) { - LXScrollingDirection oldDirection = [self.scrollingTimer.userInfo[kLXScrollingDirectionKey] integerValue]; - + if (!self.displayLink.paused) { + LXScrollingDirection oldDirection = [self.displayLink.LX_userInfo[kLXScrollingDirectionKey] integerValue]; + if (direction == oldDirection) { return; } } [self invalidatesScrollTimer]; - - self.scrollingTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 / LX_FRAMES_PER_SECOND - target:self - selector:@selector(handleScroll:) - userInfo:@{ kLXScrollingDirectionKey : @(direction) } - repeats:YES]; + + self.displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(handleScroll:)]; + self.displayLink.LX_userInfo = @{ kLXScrollingDirectionKey : @(direction) }; + + [self.displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSRunLoopCommonModes]; } #pragma mark - Target/Action methods // Tight loop, allocate memory sparely, even if they are stack allocation. -- (void)handleScroll:(NSTimer *)timer { - LXScrollingDirection direction = (LXScrollingDirection)[timer.userInfo[kLXScrollingDirectionKey] integerValue]; +- (void)handleScroll:(CADisplayLink *)displayLink { + LXScrollingDirection direction = (LXScrollingDirection)[displayLink.LX_userInfo[kLXScrollingDirectionKey] integerValue]; if (direction == LXScrollingDirectionUnknown) { return; } From 789d9a2db374084a5afe35d5f35838e496c823c0 Mon Sep 17 00:00:00 2001 From: Zach Drayer Date: Sun, 5 May 2013 10:44:21 -0700 Subject: [PATCH 07/13] Don't require the delegate to implement collectionView:itemAtIndexPath:willMoveToIndexPath: --- .../LXReorderableCollectionViewFlowLayout.h | 3 +-- .../LXReorderableCollectionViewFlowLayout.m | 6 ++++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/LXReorderableCollectionViewFlowLayout/LXReorderableCollectionViewFlowLayout.h b/LXReorderableCollectionViewFlowLayout/LXReorderableCollectionViewFlowLayout.h index 25500d3..772b96e 100755 --- a/LXReorderableCollectionViewFlowLayout/LXReorderableCollectionViewFlowLayout.h +++ b/LXReorderableCollectionViewFlowLayout/LXReorderableCollectionViewFlowLayout.h @@ -20,10 +20,9 @@ @protocol LXReorderableCollectionViewDataSource -- (void)collectionView:(UICollectionView *)collectionView itemAtIndexPath:(NSIndexPath *)fromIndexPath willMoveToIndexPath:(NSIndexPath *)toIndexPath; - @optional +- (void)collectionView:(UICollectionView *)collectionView itemAtIndexPath:(NSIndexPath *)fromIndexPath willMoveToIndexPath:(NSIndexPath *)toIndexPath; - (BOOL)collectionView:(UICollectionView *)collectionView canMoveItemAtIndexPath:(NSIndexPath *)indexPath; - (BOOL)collectionView:(UICollectionView *)collectionView itemAtIndexPath:(NSIndexPath *)fromIndexPath canMoveToIndexPath:(NSIndexPath *)toIndexPath; diff --git a/LXReorderableCollectionViewFlowLayout/LXReorderableCollectionViewFlowLayout.m b/LXReorderableCollectionViewFlowLayout/LXReorderableCollectionViewFlowLayout.m index 1ec84fd..0573038 100755 --- a/LXReorderableCollectionViewFlowLayout/LXReorderableCollectionViewFlowLayout.m +++ b/LXReorderableCollectionViewFlowLayout/LXReorderableCollectionViewFlowLayout.m @@ -154,8 +154,10 @@ - (void)invalidateLayoutIfNecessary { self.selectedItemIndexPath = newIndexPath; - [self.dataSource collectionView:self.collectionView itemAtIndexPath:previousIndexPath willMoveToIndexPath:newIndexPath]; - + if ([self.dataSource respondsToSelector:@selector(collectionView:itemAtIndexPath:willMoveToIndexPath:)]) { + [self.dataSource collectionView:self.collectionView itemAtIndexPath:previousIndexPath willMoveToIndexPath:newIndexPath]; + } + __weak typeof(self) weakSelf = self; [self.collectionView performBatchUpdates:^{ __strong typeof(self) strongSelf = weakSelf; From 1642a721695406a07e73f1e9633ab36e0f5a4194 Mon Sep 17 00:00:00 2001 From: Zach Drayer Date: Sun, 5 May 2013 10:48:55 -0700 Subject: [PATCH 08/13] add collectionView:itemAtIndexPath:didMoveToIndexPath: --- .../LXReorderableCollectionViewFlowLayout.h | 2 ++ .../LXReorderableCollectionViewFlowLayout.m | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/LXReorderableCollectionViewFlowLayout/LXReorderableCollectionViewFlowLayout.h b/LXReorderableCollectionViewFlowLayout/LXReorderableCollectionViewFlowLayout.h index 772b96e..76617f4 100755 --- a/LXReorderableCollectionViewFlowLayout/LXReorderableCollectionViewFlowLayout.h +++ b/LXReorderableCollectionViewFlowLayout/LXReorderableCollectionViewFlowLayout.h @@ -23,6 +23,8 @@ @optional - (void)collectionView:(UICollectionView *)collectionView itemAtIndexPath:(NSIndexPath *)fromIndexPath willMoveToIndexPath:(NSIndexPath *)toIndexPath; +- (void)collectionView:(UICollectionView *)collectionView itemAtIndexPath:(NSIndexPath *)fromIndexPath didMoveToIndexPath:(NSIndexPath *)toIndexPath; + - (BOOL)collectionView:(UICollectionView *)collectionView canMoveItemAtIndexPath:(NSIndexPath *)indexPath; - (BOOL)collectionView:(UICollectionView *)collectionView itemAtIndexPath:(NSIndexPath *)fromIndexPath canMoveToIndexPath:(NSIndexPath *)toIndexPath; diff --git a/LXReorderableCollectionViewFlowLayout/LXReorderableCollectionViewFlowLayout.m b/LXReorderableCollectionViewFlowLayout/LXReorderableCollectionViewFlowLayout.m index 0573038..0250db4 100755 --- a/LXReorderableCollectionViewFlowLayout/LXReorderableCollectionViewFlowLayout.m +++ b/LXReorderableCollectionViewFlowLayout/LXReorderableCollectionViewFlowLayout.m @@ -165,7 +165,12 @@ - (void)invalidateLayoutIfNecessary { [strongSelf.collectionView deleteItemsAtIndexPaths:@[ previousIndexPath ]]; [strongSelf.collectionView insertItemsAtIndexPaths:@[ newIndexPath ]]; } - } completion:nil]; + } completion:^(BOOL finished) { + __strong typeof(self) strongSelf = weakSelf; + if ([strongSelf.dataSource respondsToSelector:@selector(collectionView:itemAtIndexPath:didMoveToIndexPath:)]) { + [strongSelf.dataSource collectionView:strongSelf.collectionView itemAtIndexPath:previousIndexPath didMoveToIndexPath:newIndexPath]; + } + }]; } - (void)invalidatesScrollTimer { From 90b8a29f173fb55f6a6837b746346f54af92a3b3 Mon Sep 17 00:00:00 2001 From: Marius Landwehr Date: Thu, 16 May 2013 18:27:08 +0200 Subject: [PATCH 09/13] Ability to costumize the scrollToNextPage and scrollToPreviousPage through delegates. --- .../LXReorderableCollectionViewFlowLayout.h | 3 +++ .../LXReorderableCollectionViewFlowLayout.m | 10 ++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/LXReorderableCollectionViewFlowLayout/LXReorderableCollectionViewFlowLayout.h b/LXReorderableCollectionViewFlowLayout/LXReorderableCollectionViewFlowLayout.h index e54ce58..cce034a 100755 --- a/LXReorderableCollectionViewFlowLayout/LXReorderableCollectionViewFlowLayout.h +++ b/LXReorderableCollectionViewFlowLayout/LXReorderableCollectionViewFlowLayout.h @@ -37,4 +37,7 @@ - (void)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout willEndDraggingItemAtIndexPath:(NSIndexPath *)indexPath; - (void)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout didEndDraggingItemAtIndexPath:(NSIndexPath *)indexPath; +- (void)collectionViewScrollToNextPage:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout; +- (void)collectionViewScrollToPreviousPage:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout; + @end \ No newline at end of file diff --git a/LXReorderableCollectionViewFlowLayout/LXReorderableCollectionViewFlowLayout.m b/LXReorderableCollectionViewFlowLayout/LXReorderableCollectionViewFlowLayout.m index 1e0cbdf..e8ff3d4 100755 --- a/LXReorderableCollectionViewFlowLayout/LXReorderableCollectionViewFlowLayout.m +++ b/LXReorderableCollectionViewFlowLayout/LXReorderableCollectionViewFlowLayout.m @@ -271,11 +271,17 @@ - (void)scrollWithDirection:(LXScrollingDirection)direction { switch(direction) { case LXScrollingDirectionUp: case LXScrollingDirectionLeft: { - [self scrollToPreviousPage]; + if([self.delegate respondsToSelector:@selector(collectionViewScrollToPreviousPage:layout:)]) + [self.delegate collectionViewScrollToPreviousPage:self.collectionView layout:self]; + else + [self scrollToPreviousPage]; } break; case LXScrollingDirectionDown: case LXScrollingDirectionRight: { - [self scrollToNextPage]; + if([self.delegate respondsToSelector:@selector(collectionViewScrollToNextPage:layout:)]) + [self.delegate collectionViewScrollToNextPage:self.collectionView layout:self]; + else + [self scrollToNextPage]; } break; default: { // Do nothing... From 1129f9708a658dc7c7751f4c62de4ac19d4c058b Mon Sep 17 00:00:00 2001 From: Stan Chang Khin Boon Date: Sun, 7 Jul 2013 22:56:15 +0800 Subject: [PATCH 10/13] - Updates README to includes alternative libraries. --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index fd65fc5..ef79823 100644 --- a/README.md +++ b/README.md @@ -62,6 +62,11 @@ Credits - Refactored by [Luke Scott](https://github.com/lukescott), with some help from [mulle-nat's fork](https://github.com/mulle-nat/LXReorderableCollectionViewFlowLayout). - Playing cards in the demo are downloaded from [http://www.jfitz.com/cards/](http://www.jfitz.com/cards/). +Alternatives +============ + +- [DraggableCollectionView](https://github.com/lukescott/DraggableCollectionView) by [Luke Scott](https://github.com/lukescott). + License ======= From 366b83ed5f67f65bac2aa0a734c721436053c015 Mon Sep 17 00:00:00 2001 From: Marius Landwehr Date: Wed, 10 Jul 2013 17:30:23 +0200 Subject: [PATCH 11/13] [BUGFIX] @end added --- .../LXReorderableCollectionViewFlowLayout.m | 2 ++ 1 file changed, 2 insertions(+) diff --git a/LXReorderableCollectionViewFlowLayout/LXReorderableCollectionViewFlowLayout.m b/LXReorderableCollectionViewFlowLayout/LXReorderableCollectionViewFlowLayout.m index 3d1bd65..aa2b995 100755 --- a/LXReorderableCollectionViewFlowLayout/LXReorderableCollectionViewFlowLayout.m +++ b/LXReorderableCollectionViewFlowLayout/LXReorderableCollectionViewFlowLayout.m @@ -72,6 +72,8 @@ - (CGPoint)LX_contentOffsetForPageIndex:(NSInteger)pageIndex { } } +@end + @interface CADisplayLink (LX_userInfo) @property (nonatomic, copy) NSDictionary *LX_userInfo; @end From b6c7ac0f50757c9c53c63ce7e004b70a452d4130 Mon Sep 17 00:00:00 2001 From: Marius Landwehr Date: Tue, 24 Sep 2013 16:24:56 +0200 Subject: [PATCH 12/13] [Bugfix] collectionViewContentSize is fixed in iOS 7 --- .../LXReorderableCollectionViewFlowLayout.m | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/LXReorderableCollectionViewFlowLayout/LXReorderableCollectionViewFlowLayout.m b/LXReorderableCollectionViewFlowLayout/LXReorderableCollectionViewFlowLayout.m index aa2b995..d0d3a58 100755 --- a/LXReorderableCollectionViewFlowLayout/LXReorderableCollectionViewFlowLayout.m +++ b/LXReorderableCollectionViewFlowLayout/LXReorderableCollectionViewFlowLayout.m @@ -593,4 +593,20 @@ - (void)setUpGestureRecognizersOnCollectionView { // Do nothing... } +- (CGSize)collectionViewContentSize +{ + CGFloat screenHeight = [UIScreen mainScreen].bounds.size.height - 64; + CGSize collectionViewContentSize = [super collectionViewContentSize]; + if((int)collectionViewContentSize.height % (int)screenHeight != 0) + { + int numberOfPages = floor(collectionViewContentSize.height / screenHeight); + CGSize newContentSize = CGSizeMake(collectionViewContentSize.width, (screenHeight * numberOfPages) + screenHeight); + return newContentSize; + } + else + { + return [super collectionViewContentSize]; + } +} + @end From f2e4a97e478df54c5d730a9b5062d9a5b15d252f Mon Sep 17 00:00:00 2001 From: Marius Landwehr Date: Mon, 3 Aug 2015 15:22:21 +0200 Subject: [PATCH 13/13] removed strange method in collectionViewContentSize --- .../LXReorderableCollectionViewFlowLayout.m | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/LXReorderableCollectionViewFlowLayout/LXReorderableCollectionViewFlowLayout.m b/LXReorderableCollectionViewFlowLayout/LXReorderableCollectionViewFlowLayout.m index d0d3a58..aa2b995 100755 --- a/LXReorderableCollectionViewFlowLayout/LXReorderableCollectionViewFlowLayout.m +++ b/LXReorderableCollectionViewFlowLayout/LXReorderableCollectionViewFlowLayout.m @@ -593,20 +593,4 @@ - (void)setUpGestureRecognizersOnCollectionView { // Do nothing... } -- (CGSize)collectionViewContentSize -{ - CGFloat screenHeight = [UIScreen mainScreen].bounds.size.height - 64; - CGSize collectionViewContentSize = [super collectionViewContentSize]; - if((int)collectionViewContentSize.height % (int)screenHeight != 0) - { - int numberOfPages = floor(collectionViewContentSize.height / screenHeight); - CGSize newContentSize = CGSizeMake(collectionViewContentSize.width, (screenHeight * numberOfPages) + screenHeight); - return newContentSize; - } - else - { - return [super collectionViewContentSize]; - } -} - @end