Skip to content

Commit

Permalink
添加可交互性的功能
Browse files Browse the repository at this point in the history
  • Loading branch information
xhzengAIB committed Aug 14, 2014
1 parent e1e3c14 commit b7398b1
Show file tree
Hide file tree
Showing 17 changed files with 375 additions and 173 deletions.
24 changes: 18 additions & 6 deletions Example/PinterestExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
/* Begin PBXBuildFile section */
7D096EF81999B28C00C492A6 /* UICollectionView+XHIndexPath.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D096ED71999B28C00C492A6 /* UICollectionView+XHIndexPath.m */; };
7D096EF91999B28C00C492A6 /* UIView+XHViewFrame.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D096ED91999B28C00C492A6 /* UIView+XHViewFrame.m */; };
7D096EFA1999B28C00C492A6 /* XHPinterestTransition.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D096EE01999B28C00C492A6 /* XHPinterestTransition.m */; };
7D096EFB1999B28C00C492A6 /* XHNavigationControllerDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D096EE21999B28C00C492A6 /* XHNavigationControllerDelegate.m */; };
7D096EFC1999B28C00C492A6 /* CHTCollectionViewWaterfallLayout.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D096EE51999B28C00C492A6 /* CHTCollectionViewWaterfallLayout.m */; };
7D096F011999B28C00C492A6 /* XHHorizontalPageViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D096EF31999B28C00C492A6 /* XHHorizontalPageViewCell.m */; };
Expand All @@ -34,6 +33,9 @@
7D6257011973883D005D8CB7 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D6257001973883D005D8CB7 /* AppDelegate.m */; };
7D6257031973883D005D8CB7 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 7D6257021973883D005D8CB7 /* Images.xcassets */; };
7D62570F1973883D005D8CB7 /* PinterestExampleTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D62570E1973883D005D8CB7 /* PinterestExampleTests.m */; };
7D630888199C8935008A3771 /* XHPinterestPushTransition.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D630887199C8935008A3771 /* XHPinterestPushTransition.m */; };
7D63088B199C893F008A3771 /* XHPinterestPopTransition.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D63088A199C893F008A3771 /* XHPinterestPopTransition.m */; };
7D63088E199C894B008A3771 /* XHPinterestTransition.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D63088D199C894B008A3771 /* XHPinterestTransition.m */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand All @@ -52,8 +54,6 @@
7D096ED81999B28C00C492A6 /* UIView+XHViewFrame.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIView+XHViewFrame.h"; sourceTree = "<group>"; };
7D096ED91999B28C00C492A6 /* UIView+XHViewFrame.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIView+XHViewFrame.m"; sourceTree = "<group>"; };
7D096EDE1999B28C00C492A6 /* XHTransitionProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XHTransitionProtocol.h; sourceTree = "<group>"; };
7D096EDF1999B28C00C492A6 /* XHPinterestTransition.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XHPinterestTransition.h; sourceTree = "<group>"; };
7D096EE01999B28C00C492A6 /* XHPinterestTransition.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = XHPinterestTransition.m; sourceTree = "<group>"; };
7D096EE11999B28C00C492A6 /* XHNavigationControllerDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XHNavigationControllerDelegate.h; sourceTree = "<group>"; };
7D096EE21999B28C00C492A6 /* XHNavigationControllerDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = XHNavigationControllerDelegate.m; sourceTree = "<group>"; };
7D096EE41999B28C00C492A6 /* CHTCollectionViewWaterfallLayout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CHTCollectionViewWaterfallLayout.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -94,6 +94,12 @@
7D6257081973883D005D8CB7 /* PinterestExampleTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = PinterestExampleTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
7D62570D1973883D005D8CB7 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
7D62570E1973883D005D8CB7 /* PinterestExampleTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = PinterestExampleTests.m; sourceTree = "<group>"; };
7D630886199C8935008A3771 /* XHPinterestPushTransition.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XHPinterestPushTransition.h; sourceTree = "<group>"; };
7D630887199C8935008A3771 /* XHPinterestPushTransition.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = XHPinterestPushTransition.m; sourceTree = "<group>"; };
7D630889199C893F008A3771 /* XHPinterestPopTransition.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XHPinterestPopTransition.h; sourceTree = "<group>"; };
7D63088A199C893F008A3771 /* XHPinterestPopTransition.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = XHPinterestPopTransition.m; sourceTree = "<group>"; };
7D63088C199C894B008A3771 /* XHPinterestTransition.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XHPinterestTransition.h; sourceTree = "<group>"; };
7D63088D199C894B008A3771 /* XHPinterestTransition.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = XHPinterestTransition.m; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -162,8 +168,12 @@
isa = PBXGroup;
children = (
7D096EDD1999B28C00C492A6 /* Protocal */,
7D096EDF1999B28C00C492A6 /* XHPinterestTransition.h */,
7D096EE01999B28C00C492A6 /* XHPinterestTransition.m */,
7D63088C199C894B008A3771 /* XHPinterestTransition.h */,
7D63088D199C894B008A3771 /* XHPinterestTransition.m */,
7D630886199C8935008A3771 /* XHPinterestPushTransition.h */,
7D630887199C8935008A3771 /* XHPinterestPushTransition.m */,
7D630889199C893F008A3771 /* XHPinterestPopTransition.h */,
7D63088A199C893F008A3771 /* XHPinterestPopTransition.m */,
);
path = Transition;
sourceTree = "<group>";
Expand Down Expand Up @@ -422,10 +432,12 @@
7D096F0E1999B2A900C492A6 /* XHHorizontalPageViewController.m in Sources */,
7D096F011999B28C00C492A6 /* XHHorizontalPageViewCell.m in Sources */,
7D096EFC1999B28C00C492A6 /* CHTCollectionViewWaterfallLayout.m in Sources */,
7D096EFA1999B28C00C492A6 /* XHPinterestTransition.m in Sources */,
7D63088E199C894B008A3771 /* XHPinterestTransition.m in Sources */,
7D6257011973883D005D8CB7 /* AppDelegate.m in Sources */,
7D096F0F1999B2A900C492A6 /* XHNavigationController.m in Sources */,
7D6256FE1973883D005D8CB7 /* main.m in Sources */,
7D630888199C8935008A3771 /* XHPinterestPushTransition.m in Sources */,
7D63088B199C893F008A3771 /* XHPinterestPopTransition.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ @implementation XHHorizontalPageViewController
- (UICollectionView *)collectionView {
if (!_collectionView){
_collectionView = [[UICollectionView alloc] initWithFrame:self.view.bounds collectionViewLayout:self.collectionViewFlowLayout];
[_collectionView setScrollsToTop:NO];
_collectionView.delegate = self;
_collectionView.dataSource = self;
[_collectionView registerClass:[XHHorizontalPageViewCell class] forCellWithReuseIdentifier:kXHHorizontalPageViewCellIdentify];
Expand Down
9 changes: 5 additions & 4 deletions PinterestAnimator/Controllers/XHWaterfallViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ @implementation XHWaterfallViewController
#pragma mark - Propertys

- (XHNavigationControllerDelegate *)navigationControllerDelegate {
if (!_navigationControllerDelegate) {
_navigationControllerDelegate = [[XHNavigationControllerDelegate alloc] init];
}
return _navigationControllerDelegate;
}

Expand All @@ -36,7 +33,11 @@ - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.title = @"Pinterest";
self.navigationController.delegate = self.navigationControllerDelegate;

if (!_navigationControllerDelegate) {
_navigationControllerDelegate = [[XHNavigationControllerDelegate alloc] initWithNavigationController:self.navigationController
panGestureRecognizerEnable:NO];
}
}

- (void)didReceiveMemoryWarning {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// XHPinterestPopTransition.h
// PinterestExample
//
// Created by dw_iOS on 14-8-14.
// Copyright (c) 2014年 广州华多网络科技有限公司 多玩事业部 iOS软件工程师 曾宪华. All rights reserved.
//

#import <Foundation/Foundation.h>

#import "XHPinterestTransition.h"

@interface XHPinterestPopTransition : XHPinterestTransition

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
//
// XHPinterestPopTransition.m
// PinterestExample
//
// Created by dw_iOS on 14-8-14.
// Copyright (c) 2014年 广州华多网络科技有限公司 多玩事业部 iOS软件工程师 曾宪华. All rights reserved.
//

#import "XHPinterestPopTransition.h"

@implementation XHPinterestPopTransition

- (void)animateTransition:(id <UIViewControllerContextTransitioning>)transitionContext {

UIViewController <XHTransitionProtocol> *fromViewController = (UIViewController <XHTransitionProtocol> * )([transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey]);

UIViewController <XHTransitionProtocol> *toViewController = (UIViewController <XHTransitionProtocol> * )([transitionContext viewControllerForKey:UITransitionContextToViewControllerKey]);

UIView *containerView = [transitionContext containerView];

UIView *toView = toViewController.view;

[containerView addSubview:toView];
toView.hidden = YES;

UICollectionView *waterFallView = [toViewController transitionCollectionView];

UICollectionView *pageView = [fromViewController transitionCollectionView];


[waterFallView layoutIfNeeded];

NSIndexPath *indexPath = pageView.currentIndexPath;

UIView <XHTansitionWaterfallGridViewProtocol> *gridView = (UIView <XHTansitionWaterfallGridViewProtocol> *)([waterFallView cellForItemAtIndexPath:indexPath]);

[waterFallView performBatchUpdates:^{

} completion:NULL];


CGPoint leftUpperPoint = [gridView convertPoint:CGPointZero toView:nil];

UIView *snapShot = [gridView snapShotForTransition];

CGFloat animationScale = [self animationScale];

snapShot.transform = CGAffineTransformMakeScale(animationScale, animationScale);

CGFloat pullOffsetY = [(UIViewController <XHHorizontalPageViewControllerProtocol> *)fromViewController pageViewCellScrollViewContentOffset].y;

CGFloat offsetY = fromViewController.navigationController.navigationBarHidden ? 0.0 : 64;
[snapShot setOrigin:CGPointMake(kXHLargeGridItemPadding, -pullOffsetY+offsetY + kXHLargeGridItemPadding)];

[containerView addSubview:snapShot];


toView.hidden = NO;

toView.alpha = 0.0;
toView.transform = snapShot.transform;

toView.frame = CGRectMake(-(leftUpperPoint.x * animationScale), -((leftUpperPoint.y-offsetY) * animationScale + pullOffsetY+offsetY),
toView.frame.size.width, toView.frame.size.height);


UIView *whiteViewContainer = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

whiteViewContainer.backgroundColor = [UIColor whiteColor];

[containerView addSubview:whiteViewContainer];
[containerView insertSubview:whiteViewContainer belowSubview:toView];

[UIView animateWithDuration:[self animationDuration] animations:^{
snapShot.transform = CGAffineTransformIdentity;
[snapShot setOrigin:leftUpperPoint];

toView.transform = CGAffineTransformIdentity;
[toView setOrigin:CGPointZero];
toView.alpha = 1.0;

} completion:^(BOOL finished) {
if (finished) {
[snapShot removeFromSuperview];
[whiteViewContainer removeFromSuperview];
[transitionContext completeTransition:!self.canceled];
}

}];
}

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// XHPinterestPushTransition.h
// PinterestExample
//
// Created by dw_iOS on 14-8-14.
// Copyright (c) 2014年 广州华多网络科技有限公司 多玩事业部 iOS软件工程师 曾宪华. All rights reserved.
//

#import <Foundation/Foundation.h>

#import "XHPinterestTransition.h"

@interface XHPinterestPushTransition : XHPinterestTransition

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
//
// XHPinterestPushTransition.m
// PinterestExample
//
// Created by dw_iOS on 14-8-14.
// Copyright (c) 2014年 广州华多网络科技有限公司 多玩事业部 iOS软件工程师 曾宪华. All rights reserved.
//

#import "XHPinterestPushTransition.h"

@implementation XHPinterestPushTransition

- (void)animateTransition:(id <UIViewControllerContextTransitioning>)transitionContext {

UIViewController <XHTransitionProtocol> *fromViewController = (UIViewController <XHTransitionProtocol> * )([transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey]);

UIViewController <XHTransitionProtocol> *toViewController = (UIViewController <XHTransitionProtocol> * )([transitionContext viewControllerForKey:UITransitionContextToViewControllerKey]);

UIView *containerView = [transitionContext containerView];

UIView *fromView = fromViewController.view;
UIView *toView = toViewController.view;

UICollectionView *waterFallView = [fromViewController transitionCollectionView];

UICollectionView *pageView = [toViewController transitionCollectionView];

[containerView addSubview:fromView];
[containerView addSubview:toView];

NSIndexPath *indexPath = [waterFallView currentIndexPath];

UIView <XHTansitionWaterfallGridViewProtocol> *gridView = (UIView <XHTansitionWaterfallGridViewProtocol> *)([waterFallView cellForItemAtIndexPath:indexPath]);

CGPoint leftUpperPoint = [gridView convertPoint:CGPointZero toView:nil];

pageView.hidden = YES;

[pageView scrollToItemAtIndexPath:indexPath atScrollPosition:UICollectionViewScrollPositionCenteredVertically animated:NO];

CGFloat offsetY = fromViewController.navigationController.navigationBarHidden ? 0.0 : 64;


CGFloat offsetStatuBar = fromViewController.navigationController.navigationBarHidden ? 0.0 : 64;

UIView *snapShot = [gridView snapShotForTransition];
[containerView addSubview:snapShot];
[snapShot setOrigin:leftUpperPoint];

CGFloat animationScale = [self animationScale];
[UIView animateWithDuration:[self animationDuration] animations:^{

snapShot.transform = CGAffineTransformMakeScale(animationScale,
animationScale);

[snapShot setOrigin:CGPointMake(kXHLargeGridItemPadding, offsetY + kXHLargeGridItemPadding)];

fromView.alpha = 0;
fromView.transform = snapShot.transform;
fromView.frame = CGRectMake(-(leftUpperPoint.x)*animationScale,
-(leftUpperPoint.y-offsetStatuBar)*animationScale+offsetStatuBar,
fromView.frame.size.width,
fromView.frame.size.height);

} completion:^(BOOL finished) {
if (finished) {
[snapShot removeFromSuperview];
pageView.hidden = NO;
fromView.transform = CGAffineTransformIdentity;
[transitionContext completeTransition:!self.canceled];
}
}];
}


@end
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,27 @@
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

#import "XHTransitionProtocol.h"

#import "UICollectionView+XHIndexPath.h"
#import "UIView+XHViewFrame.h"
#import "XHUIKitMacro.h"

@interface XHPinterestTransition : NSObject <UIViewControllerAnimatedTransitioning>

/**
* 缩放参数
*/
@property (nonatomic, assign) CGFloat animationScale;

/**
* 动画参数
*/
@property (nonatomic, assign) NSTimeInterval animationDuration;

/**
* 用于标记push或者pop
* 用于可交互性的控制数据,不过有个bug,后续找方案解决
*/
@property (nonatomic, assign) UINavigationControllerOperation operation;
@property (nonatomic, assign) BOOL canceled;

@end
Loading

0 comments on commit b7398b1

Please sign in to comment.