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/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 ab112b2..74ee4e5 100755
--- a/Paper/HATransitionController.m
+++ b/Paper/HATransitionController.m
@@ -8,6 +8,8 @@
#import "HATransitionController.h"
#import "HATransitionLayout.h"
+#import "HACollectionViewLargeLayout.h"
+
@interface HATransitionController ()
@@ -17,6 +19,11 @@ @interface HATransitionController ()
@property (nonatomic) CGPoint initialPinchPoint;
@property (nonatomic) CGFloat initialScale;
+@property (nonatomic) NSIndexPath *cellIndexPath;
+@property (nonatomic) BOOL isInitial;
+@property (nonatomic) CGFloat targetY;
+
+
@end
@@ -78,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;
@@ -207,7 +219,108 @@ - (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;
+ }
+
}
+- (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
diff --git a/Paper/HATransitionLayout.m b/Paper/HATransitionLayout.m
index 61c1ca2..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;
}