From 4b561255345d9e0eefe4c695e711290538678509 Mon Sep 17 00:00:00 2001 From: Simay Date: Thu, 28 Apr 2016 23:04:18 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=8D=95=E6=89=8B?= =?UTF-8?q?=E6=8C=87=E6=8B=96=E6=8B=BD=E5=8F=98=E5=A4=A7=E5=8F=98=E5=B0=8F?= =?UTF-8?q?=E7=9A=84=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xcschemes/Paper.xcscheme | 101 ++++++++++++++++++ .../xcschemes/xcschememanagement.plist | 27 +++++ Paper/HATransitionController.m | 86 ++++++++++++++- Paper/HATransitionLayout.m | 2 +- 4 files changed, 214 insertions(+), 2 deletions(-) create mode 100644 Paper.xcodeproj/xcuserdata/Simay.xcuserdatad/xcschemes/Paper.xcscheme create mode 100644 Paper.xcodeproj/xcuserdata/Simay.xcuserdatad/xcschemes/xcschememanagement.plist diff --git a/Paper.xcodeproj/xcuserdata/Simay.xcuserdatad/xcschemes/Paper.xcscheme b/Paper.xcodeproj/xcuserdata/Simay.xcuserdatad/xcschemes/Paper.xcscheme new file mode 100644 index 0000000..6e836de --- /dev/null +++ b/Paper.xcodeproj/xcuserdata/Simay.xcuserdatad/xcschemes/Paper.xcscheme @@ -0,0 +1,101 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Paper.xcodeproj/xcuserdata/Simay.xcuserdatad/xcschemes/xcschememanagement.plist b/Paper.xcodeproj/xcuserdata/Simay.xcuserdatad/xcschemes/xcschememanagement.plist new file mode 100644 index 0000000..98c4bdb --- /dev/null +++ b/Paper.xcodeproj/xcuserdata/Simay.xcuserdatad/xcschemes/xcschememanagement.plist @@ -0,0 +1,27 @@ + + + + + SchemeUserState + + Paper.xcscheme + + orderHint + 0 + + + SuppressBuildableAutocreation + + 1AA0CC1418A07EBC008F50F6 + + primary + + + 1AA0CC3518A07EBC008F50F6 + + primary + + + + + diff --git a/Paper/HATransitionController.m b/Paper/HATransitionController.m index ab112b2..f687c37 100755 --- a/Paper/HATransitionController.m +++ b/Paper/HATransitionController.m @@ -17,6 +17,11 @@ @interface HATransitionController () @property (nonatomic) CGPoint initialPinchPoint; @property (nonatomic) CGFloat initialScale; +@property (nonatomic) NSIndexPath *cellIndexPath; +@property (nonatomic) BOOL isInitial; +@property (nonatomic) CGFloat targetY; + + @end @@ -207,7 +212,86 @@ - (void)oneFingerGesture:(UIPanGestureRecognizer *)sender CGPoint point = [sender locationInView:sender.view]; NSLog(@"point.x %f", point.x); NSLog(@"point.y %f", point.y); + + if (sender.state == UIGestureRecognizerStateEnded) + { + [self endInteractionWithSuccess:YES]; + } + else if (sender.state == UIGestureRecognizerStateCancelled) + { + [self endInteractionWithSuccess:NO]; + } + else if (sender.numberOfTouches == 1) + { + if (sender.state == UIGestureRecognizerStateBegan) + { + // start the pinch in our out + if (!self.hasActiveInteraction) + { +// 此处的记录可以使得向上拖拽变大时,用来显示最合适的cell,而不只是当前正在拖拽的cell + _cellIndexPath = [self.collectionView indexPathForItemAtPoint:point]; + self.initialPinchPoint = point; + self.isInitial = NO; + self.hasActiveInteraction = YES; // the transition is in active motion + [self.delegate interactionBeganAtPoint:point]; + + } + } + + if (self.hasActiveInteraction) + { + if (sender.state == UIGestureRecognizerStateChanged) + { + if (!self.transitionLayout) return; + if (!_isInitial) { + _isInitial = YES; + [self updateInitalDataWithPoint:point]; + } + + UIOffset offsetToUse = self.transitionLayout.offset; + CGFloat progress = ABS((point.y - _initialPinchPoint.y)/(_initialPinchPoint.y - _targetY)); + + if (self.navigationOperation == UINavigationControllerOperationPush) { + if (point.y < _targetY) { + progress = 1; + offsetToUse.vertical = point.y - _targetY; + } + else if (point.y > _initialPinchPoint.y) { + progress = 0; + offsetToUse.vertical = point.y - _initialPinchPoint.y; + } + + } + else { + if (point.y > _targetY) { + progress = 1; + offsetToUse.vertical = point.y - _targetY; + } + else if (point.y < _initialPinchPoint.y) { + progress = 0; + offsetToUse.vertical = point.y - _initialPinchPoint.y; + } + } + CGPoint translation = [sender translationInView:sender.view]; + offsetToUse.horizontal = translation.x; + [self updateWithProgress:progress andOffset:offsetToUse]; + } + } + } + +} +- (void)updateInitalDataWithPoint:(CGPoint)point { + id nextLayout = self.transitionLayout.nextLayout; + id currentLayout = self.transitionLayout.currentLayout; + if ([nextLayout isKindOfClass:[UICollectionViewFlowLayout class]] && [currentLayout isKindOfClass:[UICollectionViewFlowLayout class]]) { + + CGFloat nextHeight = ((UICollectionViewFlowLayout *)nextLayout).itemSize.height; + CGFloat currentHeight = ((UICollectionViewFlowLayout *)currentLayout).itemSize.height; + CGFloat tallHeight = MAX(nextHeight, currentHeight); + CGFloat hRatio = (tallHeight - _initialPinchPoint.y) / currentHeight; + _targetY = tallHeight - nextHeight * hRatio; + } + } - @end diff --git a/Paper/HATransitionLayout.m b/Paper/HATransitionLayout.m index 61c1ca2..c18bfe6 100755 --- a/Paper/HATransitionLayout.m +++ b/Paper/HATransitionLayout.m @@ -45,7 +45,7 @@ - (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect { if (currentAttribute.representedElementCategory != UICollectionElementCategorySupplementaryView) { CGPoint currentCenter = currentAttribute.center; - CGPoint updatedCenter = CGPointMake(currentCenter.x, currentCenter.y + self.offset.vertical); + CGPoint updatedCenter = CGPointMake(currentCenter.x , currentCenter.y + self.offset.vertical); currentAttribute.center = updatedCenter; } From 84d8a78f76a1f5399e4b27552611f80e60b4ad6e Mon Sep 17 00:00:00 2001 From: Simay Date: Thu, 28 Apr 2016 23:05:46 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=8D=95=E6=89=8B?= =?UTF-8?q?=E6=8C=87=E6=8B=96=E6=8B=BD=E6=97=B6=E6=A8=AA=E5=90=91=E6=BB=91?= =?UTF-8?q?=E5=8A=A8=E7=9A=84=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Paper/HATransitionLayout.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Paper/HATransitionLayout.m b/Paper/HATransitionLayout.m index c18bfe6..bb1ffc7 100755 --- a/Paper/HATransitionLayout.m +++ b/Paper/HATransitionLayout.m @@ -45,7 +45,7 @@ - (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect { if (currentAttribute.representedElementCategory != UICollectionElementCategorySupplementaryView) { CGPoint currentCenter = currentAttribute.center; - CGPoint updatedCenter = CGPointMake(currentCenter.x , currentCenter.y + self.offset.vertical); + CGPoint updatedCenter = CGPointMake(currentCenter.x + self.offset.horizontal, currentCenter.y + self.offset.vertical); currentAttribute.center = updatedCenter; } From 81f4dc7ab1cf43aadabcb3c5263932f4316d6f9d Mon Sep 17 00:00:00 2001 From: Simay Date: Thu, 28 Apr 2016 23:11:39 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=97=A0=E8=AE=BA?= =?UTF-8?q?=E5=90=91=E4=B8=8A=E6=8B=96=E6=8B=BD=E5=93=AA=E4=B8=AAcell?= =?UTF-8?q?=EF=BC=8C=E6=9C=80=E7=BB=88=E5=8F=AA=E6=98=BE=E7=A4=BA=E4=B8=AD?= =?UTF-8?q?=E9=97=B4=E7=9A=84cell=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Paper/HACollectionViewLargeLayout.h | 1 + Paper/HACollectionViewLargeLayout.m | 7 +++++++ Paper/HATransitionController.m | 7 +++++++ 3 files changed, 15 insertions(+) diff --git a/Paper/HACollectionViewLargeLayout.h b/Paper/HACollectionViewLargeLayout.h index 4cc0d37..5dd3ae6 100755 --- a/Paper/HACollectionViewLargeLayout.h +++ b/Paper/HACollectionViewLargeLayout.h @@ -10,5 +10,6 @@ #import "HAStickyHeaderLayout.h" @interface HACollectionViewLargeLayout : HAStickyHeaderLayout +@property (nonatomic, strong) NSIndexPath *targetIndexPath; @end diff --git a/Paper/HACollectionViewLargeLayout.m b/Paper/HACollectionViewLargeLayout.m index 43c4d75..674c900 100755 --- a/Paper/HACollectionViewLargeLayout.m +++ b/Paper/HACollectionViewLargeLayout.m @@ -62,6 +62,13 @@ - (CGPoint)targetContentOffsetForProposedContentOffset:(CGPoint)proposedContentO } return CGPointMake(proposedContentOffset.x + offsetAdjustment, proposedContentOffset.y); } +- (CGPoint)targetContentOffsetForProposedContentOffset:(CGPoint)proposedContentOffset { + if (_targetIndexPath) { + return CGPointMake(_targetIndexPath.row * (self.itemSize.width + self.minimumLineSpacing), 0); + } + + return proposedContentOffset; +} - (UICollectionViewLayoutAttributes *)layoutAttributesForSupplementaryViewOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath { UICollectionViewLayoutAttributes *attributes = [super layoutAttributesForSupplementaryViewOfKind:kind atIndexPath:indexPath]; diff --git a/Paper/HATransitionController.m b/Paper/HATransitionController.m index f687c37..6801e0a 100755 --- a/Paper/HATransitionController.m +++ b/Paper/HATransitionController.m @@ -8,6 +8,8 @@ #import "HATransitionController.h" #import "HATransitionLayout.h" +#import "HACollectionViewLargeLayout.h" + @interface HATransitionController () @@ -83,6 +85,11 @@ - (void)startInteractiveTransition:(id )tr UIView *containerView = [transitionContext containerView]; [containerView addSubview:[toCollectionViewController view]]; + id toLayout = toCollectionViewController.collectionViewLayout; + if ([toLayout isKindOfClass:[HACollectionViewLargeLayout class]]) { + ((HACollectionViewLargeLayout *)toLayout).targetIndexPath = _cellIndexPath; + } + self.transitionLayout = (HATransitionLayout *)[fromCollectionViewController.collectionView startInteractiveTransitionToCollectionViewLayout:toCollectionViewController.collectionViewLayout completion:^(BOOL didFinish, BOOL didComplete) { [self.context completeTransition:didComplete]; self.transitionLayout = nil; From 3020a9ad3c27ff9a87284bf3c53e114fab9702fc Mon Sep 17 00:00:00 2001 From: Simay Date: Fri, 29 Apr 2016 22:02:53 +0800 Subject: [PATCH 4/4] Fix the horizontal scrolling is broken. --- Paper/HATransitionController.m | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Paper/HATransitionController.m b/Paper/HATransitionController.m index 6801e0a..74ee4e5 100755 --- a/Paper/HATransitionController.m +++ b/Paper/HATransitionController.m @@ -301,4 +301,26 @@ - (void)updateInitalDataWithPoint:(CGPoint)point { } +- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer { + + if ([gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]]) { + id layout = self.collectionView.collectionViewLayout; + if ([layout isKindOfClass:[UICollectionViewFlowLayout class]]) { + CGFloat height = ((UICollectionViewFlowLayout *)layout).itemSize.height; + CGPoint point = [gestureRecognizer locationInView:gestureRecognizer.view]; + CGPoint translation = [(UIPanGestureRecognizer *)gestureRecognizer translationInView:gestureRecognizer.view]; + + //手指区域在collectionView内 + //手指是上下滑动 + if (point.y > self.collectionView.frame.size.height - height && ABS(translation.y) > ABS(translation.x)) { + return YES; + } + return NO; + } + } + return YES; +} + + + @end