From e0011d64d76d132af9813e8c4e972a7bf2cb65f8 Mon Sep 17 00:00:00 2001 From: Nicholas Tau Date: Mon, 20 May 2013 20:38:38 +0800 Subject: [PATCH 01/15] add a new function --- Classes/FlipBoardNavigationController.h | 1 + Classes/FlipBoardNavigationController.m | 29 +++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/Classes/FlipBoardNavigationController.h b/Classes/FlipBoardNavigationController.h index 7bc8d6e..77d3c65 100644 --- a/Classes/FlipBoardNavigationController.h +++ b/Classes/FlipBoardNavigationController.h @@ -20,6 +20,7 @@ typedef void (^FlipBoardNavigationControllerCompletionBlock)(void); - (void) pushViewController:(UIViewController *)viewController completion:(FlipBoardNavigationControllerCompletionBlock)handler; - (void) popViewController; - (void) popViewControllerWithCompletion:(FlipBoardNavigationControllerCompletionBlock)handler; +- (void) popViewController:(UIViewController*)viewControler withCompletion:(FlipBoardNavigationControllerCompletionBlock)handler; @end @interface UIViewController (FlipBoardNavigationController) diff --git a/Classes/FlipBoardNavigationController.m b/Classes/FlipBoardNavigationController.m index 2262344..b62c835 100644 --- a/Classes/FlipBoardNavigationController.m +++ b/Classes/FlipBoardNavigationController.m @@ -127,6 +127,35 @@ - (void) popViewControllerWithCompletion:(FlipBoardNavigationControllerCompletio } +- (void) popViewController:(UIViewController*)viewControler withCompletion:(FlipBoardNavigationControllerCompletionBlock)handler +{ + BOOL exist = NO; + for (UIViewController * subControler in self.viewControllers) + { + if(subControler==viewControler) + { + exist = YES; + break; + } + } + if (self.viewControllers.count < 2||!exist) { + return; + } + + UIViewController *currentVC = [self currentViewController]; + if(currentVC==viewControler) + { + [self popViewControllerWithCompletion:handler]; + return; + } + + [viewControler willMoveToParentViewController:nil]; + [viewControler removeFromParentViewController]; + [viewControler didMoveToParentViewController:nil]; + [self.viewControllers removeObject:currentVC]; + handler(); +} + - (void) popViewController { [self popViewControllerWithCompletion:^{}]; } From ad4c1005468f135e834937d919a260b8d8d921c6 Mon Sep 17 00:00:00 2001 From: Nicholas Tau Date: Mon, 20 May 2013 23:20:43 +0800 Subject: [PATCH 02/15] fix bug that take the wrong view controller pointer. --- Classes/FlipBoardNavigationController.m | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Classes/FlipBoardNavigationController.m b/Classes/FlipBoardNavigationController.m index b62c835..3c14f94 100644 --- a/Classes/FlipBoardNavigationController.m +++ b/Classes/FlipBoardNavigationController.m @@ -152,8 +152,9 @@ - (void) popViewController:(UIViewController*)viewControler withCompletion:(Flip [viewControler willMoveToParentViewController:nil]; [viewControler removeFromParentViewController]; [viewControler didMoveToParentViewController:nil]; - [self.viewControllers removeObject:currentVC]; - handler(); + [viewControler.view removeFromSuperview]; + [self.viewControllers removeObject:viewControler]; + handler(); } - (void) popViewController { From f81761d8bf585a49c604d7563fac09c97b5ea02c Mon Sep 17 00:00:00 2001 From: Nicholas Tau Date: Mon, 20 May 2013 23:21:50 +0800 Subject: [PATCH 03/15] add an example --- .../AnotherViewController.m | 13 +++++++++++++ .../FlipViewControllerDemo/ChildViewController.m | 15 +++++++++++++++ .../en.lproj/MainStoryboard_iPhone.storyboard | 9 ++++++--- 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/Sample/FlipViewControllerDemo/FlipViewControllerDemo/AnotherViewController.m b/Sample/FlipViewControllerDemo/FlipViewControllerDemo/AnotherViewController.m index 4c700ba..a8535ca 100644 --- a/Sample/FlipViewControllerDemo/FlipViewControllerDemo/AnotherViewController.m +++ b/Sample/FlipViewControllerDemo/FlipViewControllerDemo/AnotherViewController.m @@ -27,6 +27,19 @@ - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. + + UIButton * btn = [UIButton buttonWithType:UIButtonTypeRoundedRect]; + [btn addTarget:self + action:@selector(popController:) + forControlEvents:UIControlEventTouchUpInside]; + btn.frame =CGRectMake(100, 100, 100, 100); + [self.view addSubview:btn]; +} + +-(void)popController:(id)sender +{ + [[NSNotificationCenter defaultCenter] postNotificationName:@"TTT" + object:nil]; } - (void)didReceiveMemoryWarning diff --git a/Sample/FlipViewControllerDemo/FlipViewControllerDemo/ChildViewController.m b/Sample/FlipViewControllerDemo/FlipViewControllerDemo/ChildViewController.m index d1c6548..fb2a37b 100644 --- a/Sample/FlipViewControllerDemo/FlipViewControllerDemo/ChildViewController.m +++ b/Sample/FlipViewControllerDemo/FlipViewControllerDemo/ChildViewController.m @@ -27,6 +27,21 @@ - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. + + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(test:) + name:@"TTT" + object:nil]; +} + +-(void)test:(id)sender +{ + [self.flipboardNavigationController popViewController:self + withCompletion:^() + { + NSLog(@"finish"); + [[NSNotificationCenter defaultCenter] removeObserver:nil]; + }]; } - (void)didReceiveMemoryWarning diff --git a/Sample/FlipViewControllerDemo/FlipViewControllerDemo/en.lproj/MainStoryboard_iPhone.storyboard b/Sample/FlipViewControllerDemo/FlipViewControllerDemo/en.lproj/MainStoryboard_iPhone.storyboard index 06528a6..81504f7 100644 --- a/Sample/FlipViewControllerDemo/FlipViewControllerDemo/en.lproj/MainStoryboard_iPhone.storyboard +++ b/Sample/FlipViewControllerDemo/FlipViewControllerDemo/en.lproj/MainStoryboard_iPhone.storyboard @@ -1,5 +1,5 @@ - + @@ -85,10 +85,10 @@ - + - + @@ -112,6 +112,9 @@ + + + From 9f6c0f9884b3f07045bea35650a06ede7888bb7b Mon Sep 17 00:00:00 2001 From: Nicholas Tau Date: Fri, 7 Jun 2013 20:23:39 +0800 Subject: [PATCH 04/15] =?UTF-8?q?=E6=92=AD=E6=94=BE=E7=BD=91=E6=98=93?= =?UTF-8?q?=E6=96=B0=E9=97=BB=E7=9A=84=E5=9F=BA=E6=9C=AC=E5=AE=9E=E7=8E=B0?= =?UTF-8?q?=EF=BC=88=E7=AD=89=E5=AE=8C=E5=96=84=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Classes/FlipBoardNavigationController.h | 7 ++- Classes/FlipBoardNavigationController.m | 67 +++++++++++++++++++++---- 2 files changed, 63 insertions(+), 11 deletions(-) diff --git a/Classes/FlipBoardNavigationController.h b/Classes/FlipBoardNavigationController.h index 77d3c65..1ea01f4 100644 --- a/Classes/FlipBoardNavigationController.h +++ b/Classes/FlipBoardNavigationController.h @@ -11,9 +11,12 @@ typedef void (^FlipBoardNavigationControllerCompletionBlock)(void); @interface FlipBoardNavigationController : UIViewController - +{ + BOOL _rightPanViewProcessTouch; +} @property(nonatomic, retain) NSMutableArray *viewControllers; - +@property (nonatomic,strong) UIViewController * rightPanController; +-(void)addRightPanViewController:(UIViewController*)viewController; - (id) initWithRootViewController:(UIViewController*)rootViewController; - (void) pushViewController:(UIViewController *)viewController; diff --git a/Classes/FlipBoardNavigationController.m b/Classes/FlipBoardNavigationController.m index 3c14f94..da2ada6 100644 --- a/Classes/FlipBoardNavigationController.m +++ b/Classes/FlipBoardNavigationController.m @@ -68,7 +68,11 @@ - (void) loadView { _blackMask.alpha = 0.0; [self.view insertSubview:_blackMask atIndex:0]; } - +-(void)addRightPanViewController:(UIViewController*)viewController +{ + [self.view addSubview:viewController.view]; + [self addPanGestureToView:viewController.view]; +} #pragma mark - PushViewController With Completion Block - (void) pushViewController:(UIViewController *)viewController completion:(FlipBoardNavigationControllerCompletionBlock)handler { _animationInProgress = YES; @@ -221,6 +225,10 @@ - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceive UIViewController * vc = [self.viewControllers lastObject]; _panOrigin = vc.view.frame.origin; gestureRecognizer.enabled = YES; + if(self.rightPanController.view.frame.origin.x==0) + _rightPanViewProcessTouch = YES; + else + _rightPanViewProcessTouch = NO; return !_animationInProgress; } @@ -228,6 +236,27 @@ - (BOOL) gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecogn return YES; } +-(void)rightPanViewControllerAnimationEndWithDirection:(PanDirection)direction +{ + CGRect frame = CGRectZero; + switch (direction) + { + case PanDirectionLeft: + break; + case PanDirectionRight: + frame.origin = CGPointMake(320, 0); + default: + break; + } + frame.size = self.rightPanController.view.frame.size; + + [UIView animateWithDuration:.6 + animations:^() + { + self.rightPanController.view.frame =frame; + _animationInProgress = NO; + }]; +} - (void) gestureRecognizerDidPan:(UIPanGestureRecognizer*)panGesture { if(_animationInProgress) return; @@ -235,9 +264,36 @@ - (void) gestureRecognizerDidPan:(UIPanGestureRecognizer*)panGesture { CGFloat x = currentPoint.x + _panOrigin.x; CGFloat offset = 0; + PanDirection panDirection = PanDirectionNone; + CGPoint vel = [panGesture velocityInView:self.view]; + if (vel.x > kOffsetTrigger) { + panDirection = PanDirectionRight; + } else { + panDirection = PanDirectionLeft; + } + UIViewController * vc ; vc = [self currentViewController]; + + if((_rightPanViewProcessTouch|| + (!_rightPanViewProcessTouch&&x<0))&& + vc==[self.viewControllers lastObject]) + { + vc = self.rightPanController; + NSLog(@"come on right pan controller"); + offset = CGRectGetWidth(vc.view.frame) - x; + vc.view.frame = [self getSlidingRectForOffset:offset]; + + if (panGesture.state == UIGestureRecognizerStateEnded || panGesture.state == UIGestureRecognizerStateCancelled) { + [self rightPanViewControllerAnimationEndWithDirection:panDirection]; + + } + return; + } offset = CGRectGetWidth(vc.view.frame) - x; + NSLog(@"panOrigin.x:%f",_panOrigin.x); + NSLog(@"x:%f",x); + NSLog(@"offset:%f",offset); vc.view.frame = [self getSlidingRectForOffset:offset]; CGAffineTransform transf = CGAffineTransformIdentity; @@ -248,14 +304,7 @@ - (void) gestureRecognizerDidPan:(UIPanGestureRecognizer*)panGesture { _blackMask.alpha = newAlphaValue; - PanDirection panDirection = PanDirectionNone; - CGPoint vel = [panGesture velocityInView:self.view]; - if (vel.x > kOffsetTrigger) { - panDirection = PanDirectionRight; - } else { - panDirection = PanDirectionLeft; - } - + NSLog(@""); if (panGesture.state == UIGestureRecognizerStateEnded || panGesture.state == UIGestureRecognizerStateCancelled) { [self completeSlidingAnimationWithDirection:panDirection]; } From acc44f3f95d9d91f1759c713aa2deb973edf0c88 Mon Sep 17 00:00:00 2001 From: Nicholas Tau Date: Fri, 7 Jun 2013 20:24:06 +0800 Subject: [PATCH 05/15] =?UTF-8?q?demo=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FlipViewControllerDemo/ViewController.m | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/Sample/FlipViewControllerDemo/FlipViewControllerDemo/ViewController.m b/Sample/FlipViewControllerDemo/FlipViewControllerDemo/ViewController.m index 9ad5c92..8448cb3 100644 --- a/Sample/FlipViewControllerDemo/FlipViewControllerDemo/ViewController.m +++ b/Sample/FlipViewControllerDemo/FlipViewControllerDemo/ViewController.m @@ -8,6 +8,7 @@ #import "ViewController.h" #import "FlipBoardNavigationController.h" + @interface ViewController () @end @@ -27,7 +28,21 @@ - (void)didReceiveMemoryWarning } - (IBAction)push:(UIButton *)sender { - UIViewController * page = [self.storyboard instantiateViewControllerWithIdentifier:@"child_vc"]; - [self.flipboardNavigationController pushViewController:page]; +// UIViewController * page = [self.storyboard instantiateViewControllerWithIdentifier:@"child_vc"]; +// [self.flipboardNavigationController pushViewController:page]; +// +// return; + UIViewController * controller = [[UIViewController alloc] init]; + controller.view.backgroundColor = [UIColor purpleColor]; + + UIViewController * panController = [[UIViewController alloc] init]; + panController.view.backgroundColor = [UIColor grayColor]; + + self.flipboardNavigationController.rightPanController =panController; + [self.flipboardNavigationController pushViewController:controller]; + + panController.view.center =CGPointMake(panController.view.frame.size.width*1.5 , + panController.view.frame.size.height/2); + [self.flipboardNavigationController addRightPanViewController:panController]; } @end From 11c7385648aa285efe07dbadce9d8781c49cacb8 Mon Sep 17 00:00:00 2001 From: Nicholas Tau Date: Fri, 7 Jun 2013 23:28:54 +0800 Subject: [PATCH 06/15] =?UTF-8?q?=E5=9F=BA=E6=9C=AC=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E5=AE=8C=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Classes/FlipBoardNavigationController.m | 26 ++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/Classes/FlipBoardNavigationController.m b/Classes/FlipBoardNavigationController.m index da2ada6..4d5e4aa 100644 --- a/Classes/FlipBoardNavigationController.m +++ b/Classes/FlipBoardNavigationController.m @@ -13,6 +13,7 @@ static const CGFloat kAnimationDelay = 0.0f; static const CGFloat kOffsetTrigger = 30.0f; static const CGFloat kMaxBlackMaskAlpha = 0.8f; +static const CGFloat kViewScaleSize = 0.95f; typedef enum { @@ -84,7 +85,7 @@ - (void) pushViewController:(UIViewController *)viewController completion:(FlipB [self.view addSubview:viewController.view]; [UIView animateWithDuration:kAnimationDuration delay:kAnimationDelay options:0 animations:^{ CGAffineTransform transf = CGAffineTransformIdentity; - [self currentViewController].view.transform = CGAffineTransformScale(transf, 0.9f, 0.9f); + [self currentViewController].view.transform = CGAffineTransformScale(transf, kViewScaleSize, kViewScaleSize); viewController.view.frame = self.view.bounds; _blackMask.alpha = kMaxBlackMaskAlpha; } completion:^(BOOL finished) { @@ -174,7 +175,7 @@ - (void) rollBackViewController { self.view.transform = self.view.transform; [UIView animateWithDuration:((vc.view.frame.origin.x *kAnimationDuration)/self.view.frame.size.width) delay:kAnimationDelay options:0 animations:^{ CGAffineTransform transf = CGAffineTransformIdentity; - nvc.view.transform = CGAffineTransformScale(transf, 0.9f, 0.9f); + nvc.view.transform = CGAffineTransformScale(transf, kViewScaleSize, kViewScaleSize); vc.view.frame = rect; _blackMask.alpha = kMaxBlackMaskAlpha; } completion:^(BOOL finished) { @@ -238,6 +239,7 @@ - (BOOL) gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecogn -(void)rightPanViewControllerAnimationEndWithDirection:(PanDirection)direction { + _animationInProgress = YES; CGRect frame = CGRectZero; switch (direction) { @@ -250,7 +252,7 @@ -(void)rightPanViewControllerAnimationEndWithDirection:(PanDirection)direction } frame.size = self.rightPanController.view.frame.size; - [UIView animateWithDuration:.6 + [UIView animateWithDuration:((self.rightPanController.view.frame.origin.x *kAnimationDuration)/self.view.frame.size.width) animations:^() { self.rightPanController.view.frame =frame; @@ -275,9 +277,22 @@ - (void) gestureRecognizerDidPan:(UIPanGestureRecognizer*)panGesture { UIViewController * vc ; vc = [self currentViewController]; - if((_rightPanViewProcessTouch|| - (!_rightPanViewProcessTouch&&x<0))&& + if(((!_rightPanViewProcessTouch)&&x<0)&& vc==[self.viewControllers lastObject]) + { + NSLog(@"move In"); + vc = self.rightPanController; + offset = -x; + NSLog(@"offset:%f",offset); + vc.view.frame = [self getSlidingRectForOffset:offset]; + NSLog(@"%@",NSStringFromCGRect(vc.view.frame)); + if (panGesture.state == UIGestureRecognizerStateEnded || panGesture.state == UIGestureRecognizerStateCancelled) { + [self rightPanViewControllerAnimationEndWithDirection:panDirection]; + + } + return; + } + if(_rightPanViewProcessTouch) { vc = self.rightPanController; NSLog(@"come on right pan controller"); @@ -297,6 +312,7 @@ - (void) gestureRecognizerDidPan:(UIPanGestureRecognizer*)panGesture { vc.view.frame = [self getSlidingRectForOffset:offset]; CGAffineTransform transf = CGAffineTransformIdentity; + NSLog(@"offset:%f",offset); CGFloat newTransformValue = 1 - (offset/(self.view.frame.size.width/10))/100; CGFloat newAlphaValue = (offset/self.view.frame.size.width)* kMaxBlackMaskAlpha; From 7681fad25ff1ce56fb73924da9adecc7bced1914 Mon Sep 17 00:00:00 2001 From: Nicholas Tau Date: Sat, 8 Jun 2013 17:54:43 +0800 Subject: [PATCH 07/15] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=96=B0=E6=96=87?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../project.pbxproj | 20 +++++++++++++++++++ .../FlipViewControllerDemo/UIView+Util.h | 13 ++++++++++++ .../FlipViewControllerDemo/UIView+Util.m | 13 ++++++++++++ 3 files changed, 46 insertions(+) create mode 100644 Sample/FlipViewControllerDemo/FlipViewControllerDemo/UIView+Util.h create mode 100644 Sample/FlipViewControllerDemo/FlipViewControllerDemo/UIView+Util.m diff --git a/Sample/FlipViewControllerDemo/FlipViewControllerDemo.xcodeproj/project.pbxproj b/Sample/FlipViewControllerDemo/FlipViewControllerDemo.xcodeproj/project.pbxproj index 148133c..3a6b66a 100644 --- a/Sample/FlipViewControllerDemo/FlipViewControllerDemo.xcodeproj/project.pbxproj +++ b/Sample/FlipViewControllerDemo/FlipViewControllerDemo.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 2849886C176325DA0079F801 /* UIView+Util.m in Sources */ = {isa = PBXBuildFile; fileRef = 2849886B176325DA0079F801 /* UIView+Util.m */; }; 99B0A1061731743800253408 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 99B0A1051731743800253408 /* UIKit.framework */; }; 99B0A1081731743800253408 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 99B0A1071731743800253408 /* Foundation.framework */; }; 99B0A10A1731743800253408 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 99B0A1091731743800253408 /* CoreGraphics.framework */; }; @@ -43,6 +44,8 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ + 2849886A176325DA0079F801 /* UIView+Util.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIView+Util.h"; sourceTree = ""; }; + 2849886B176325DA0079F801 /* UIView+Util.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIView+Util.m"; sourceTree = ""; }; 99B0A1021731743800253408 /* FlipViewControllerDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = FlipViewControllerDemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; 99B0A1051731743800253408 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; }; 99B0A1071731743800253408 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; @@ -139,6 +142,8 @@ 99B0A143173174FB00253408 /* Classes */, 99B0A1141731743800253408 /* AppDelegate.h */, 99B0A1151731743800253408 /* AppDelegate.m */, + 2849886A176325DA0079F801 /* UIView+Util.h */, + 2849886B176325DA0079F801 /* UIView+Util.m */, 99B0A11D1731743800253408 /* MainStoryboard_iPhone.storyboard */, 99B0A1201731743800253408 /* MainStoryboard_iPad.storyboard */, 99B0A1231731743800253408 /* ViewController.h */, @@ -216,6 +221,7 @@ 99B0A0FE1731743800253408 /* Sources */, 99B0A0FF1731743800253408 /* Frameworks */, 99B0A1001731743800253408 /* Resources */, + 285BE8241761B85D00250AC9 /* ShellScript */, ); buildRules = ( ); @@ -300,6 +306,19 @@ /* End PBXResourcesBuildPhase section */ /* Begin PBXShellScriptBuildPhase section */ + 285BE8241761B85D00250AC9 /* ShellScript */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "echo \"$CODESIGNING_FOLDER_PATH\" >/tmp/\"$USER.ident\" && echo \"$CODE_SIGN_IDENTITY\" >>/tmp/\"$USER.ident\" && exit;"; + }; 99B0A1291731743800253408 /* ShellScript */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; @@ -326,6 +345,7 @@ 99B0A146173174FB00253408 /* FlipBoardNavigationController.m in Sources */, 99B0A15017317AF000253408 /* ChildViewController.m in Sources */, 99B0A15317317C7400253408 /* AnotherViewController.m in Sources */, + 2849886C176325DA0079F801 /* UIView+Util.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Sample/FlipViewControllerDemo/FlipViewControllerDemo/UIView+Util.h b/Sample/FlipViewControllerDemo/FlipViewControllerDemo/UIView+Util.h new file mode 100644 index 0000000..a823bff --- /dev/null +++ b/Sample/FlipViewControllerDemo/FlipViewControllerDemo/UIView+Util.h @@ -0,0 +1,13 @@ +// +// UIView+Util.h +// FlipViewControllerDemo +// +// Created by demon on 6/8/13. +// Copyright (c) 2013 Michael Henry Pantaleon. All rights reserved. +// + +#import + +@interface UIView (Util) + +@end diff --git a/Sample/FlipViewControllerDemo/FlipViewControllerDemo/UIView+Util.m b/Sample/FlipViewControllerDemo/FlipViewControllerDemo/UIView+Util.m new file mode 100644 index 0000000..eb5b238 --- /dev/null +++ b/Sample/FlipViewControllerDemo/FlipViewControllerDemo/UIView+Util.m @@ -0,0 +1,13 @@ +// +// UIView+Util.m +// FlipViewControllerDemo +// +// Created by demon on 6/8/13. +// Copyright (c) 2013 Michael Henry Pantaleon. All rights reserved. +// + +#import "UIView+Util.h" + +@implementation UIView (Util) + +@end From 8f0bb08bfb44b6516036c3cf2bc88388df179b1a Mon Sep 17 00:00:00 2001 From: Nicholas Tau Date: Sat, 8 Jun 2013 17:55:03 +0800 Subject: [PATCH 08/15] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=88=86=E7=B1=BB?= =?UTF-8?q?=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FlipViewControllerDemo/UIView+Util.h | 3 ++- .../FlipViewControllerDemo/UIView+Util.m | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Sample/FlipViewControllerDemo/FlipViewControllerDemo/UIView+Util.h b/Sample/FlipViewControllerDemo/FlipViewControllerDemo/UIView+Util.h index a823bff..de1666a 100644 --- a/Sample/FlipViewControllerDemo/FlipViewControllerDemo/UIView+Util.h +++ b/Sample/FlipViewControllerDemo/FlipViewControllerDemo/UIView+Util.h @@ -9,5 +9,6 @@ #import @interface UIView (Util) - +-(void)exchangeSubview:(UIView*)view1 + withSubview:(UIView*)view2; @end diff --git a/Sample/FlipViewControllerDemo/FlipViewControllerDemo/UIView+Util.m b/Sample/FlipViewControllerDemo/FlipViewControllerDemo/UIView+Util.m index eb5b238..10d6f83 100644 --- a/Sample/FlipViewControllerDemo/FlipViewControllerDemo/UIView+Util.m +++ b/Sample/FlipViewControllerDemo/FlipViewControllerDemo/UIView+Util.m @@ -10,4 +10,13 @@ @implementation UIView (Util) +-(void)exchangeSubview:(UIView*)view1 + withSubview:(UIView*)view2 +{ + int index1 = [self.subviews indexOfObject:view1]; + int index2 = [self.subviews indexOfObject:view2]; + [self exchangeSubviewAtIndex:index1 + withSubviewAtIndex:index2]; +} + @end From ea002a19f3b17ee9a9fc56c78b31025e963f5b74 Mon Sep 17 00:00:00 2001 From: Nicholas Tau Date: Sat, 8 Jun 2013 18:01:13 +0800 Subject: [PATCH 09/15] =?UTF-8?q?=E5=8A=9F=E8=83=BD=E5=AE=8C=E6=88=90?= =?UTF-8?q?=EF=BC=8C=E4=BB=A3=E7=A0=81=E7=BB=93=E6=9E=84=E5=B8=A6=E5=AE=8C?= =?UTF-8?q?=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Classes/FlipBoardNavigationController.h | 7 +- Classes/FlipBoardNavigationController.m | 92 +++++++++++++++++-------- 2 files changed, 71 insertions(+), 28 deletions(-) diff --git a/Classes/FlipBoardNavigationController.h b/Classes/FlipBoardNavigationController.h index 1ea01f4..238ecc2 100644 --- a/Classes/FlipBoardNavigationController.h +++ b/Classes/FlipBoardNavigationController.h @@ -7,12 +7,17 @@ // #import +#import "UIView+Util.h" typedef void (^FlipBoardNavigationControllerCompletionBlock)(void); @interface FlipBoardNavigationController : UIViewController { - BOOL _rightPanViewProcessTouch; + CGPoint _rightPanViewCenterPoint; + BOOL _originTouchProcess; + BOOL _rightTouchProcess; + + UIView * _view_mask_fake; } @property(nonatomic, retain) NSMutableArray *viewControllers; @property (nonatomic,strong) UIViewController * rightPanController; diff --git a/Classes/FlipBoardNavigationController.m b/Classes/FlipBoardNavigationController.m index 4d5e4aa..52f08b6 100644 --- a/Classes/FlipBoardNavigationController.m +++ b/Classes/FlipBoardNavigationController.m @@ -68,6 +68,7 @@ - (void) loadView { _blackMask.backgroundColor = [UIColor blackColor]; _blackMask.alpha = 0.0; [self.view insertSubview:_blackMask atIndex:0]; + } -(void)addRightPanViewController:(UIViewController*)viewController { @@ -214,22 +215,19 @@ - (void) addPanGestureToView:(UIView*)view UIPanGestureRecognizer* panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(gestureRecognizerDidPan:)]; panGesture.cancelsTouchesInView = YES; + panGesture.maximumNumberOfTouches = 1; panGesture.delegate = self; [view addGestureRecognizer:panGesture]; [_gestures addObject:panGesture]; - panGesture = nil; -} +} #pragma mark - Gesture recognizer - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch { UIViewController * vc = [self.viewControllers lastObject]; _panOrigin = vc.view.frame.origin; gestureRecognizer.enabled = YES; - if(self.rightPanController.view.frame.origin.x==0) - _rightPanViewProcessTouch = YES; - else - _rightPanViewProcessTouch = NO; + _rightPanViewCenterPoint = self.rightPanController.view.center; return !_animationInProgress; } @@ -255,7 +253,20 @@ -(void)rightPanViewControllerAnimationEndWithDirection:(PanDirection)direction [UIView animateWithDuration:((self.rightPanController.view.frame.origin.x *kAnimationDuration)/self.view.frame.size.width) animations:^() { + if(direction==PanDirectionRight) + { + [self.view exchangeSubview:[self currentViewController].view + withSubview:_blackMask]; + } self.rightPanController.view.frame =frame; + CGFloat newAlpha = direction==PanDirectionLeft?kMaxBlackMaskAlpha:0.0; + _blackMask.alpha = newAlpha; + + CGAffineTransform transf = CGAffineTransformIdentity; + CGFloat newTransformValue = direction==PanDirectionLeft?kViewScaleSize:1.0; + [self currentViewController].view.transform = CGAffineTransformScale(transf,newTransformValue,newTransformValue); + if(direction==PanDirectionRight) + [self currentViewController].view.userInteractionEnabled = YES; _animationInProgress = NO; }]; } @@ -274,37 +285,64 @@ - (void) gestureRecognizerDidPan:(UIPanGestureRecognizer*)panGesture { panDirection = PanDirectionLeft; } - UIViewController * vc ; - vc = [self currentViewController]; + BOOL moveLeft = vel.x<1; + UIViewController * vc= [self currentViewController]; - if(((!_rightPanViewProcessTouch)&&x<0)&& - vc==[self.viewControllers lastObject]) + if(self.rightPanController.view.frame.origin.x==0&&moveLeft) + return; + if(self.rightPanController&&//是否存在右侧的panViewController + ((moveLeft&&_rightPanController.view.center.x>160)||//向左滑入rightPanView + (!moveLeft&&_rightPanController.view.center.x<480))&&//向右推出rightPanView + !_originTouchProcess)//当前是否正在处理原有的touch事件 { - NSLog(@"move In"); + NSLog(@"enter rightPan process"); + if([self.view.subviews indexOfObject:self.currentViewController.view]> + [self.view.subviews indexOfObject:_blackMask]) + { + [self.view exchangeSubview:[self currentViewController].view + withSubview:_blackMask]; + } + [self currentViewController].view.userInteractionEnabled = NO; + _rightTouchProcess = YES; vc = self.rightPanController; - offset = -x; - NSLog(@"offset:%f",offset); - vc.view.frame = [self getSlidingRectForOffset:offset]; - NSLog(@"%@",NSStringFromCGRect(vc.view.frame)); - if (panGesture.state == UIGestureRecognizerStateEnded || panGesture.state == UIGestureRecognizerStateCancelled) { - [self rightPanViewControllerAnimationEndWithDirection:panDirection]; - + CGPoint center = CGPointMake(_rightPanViewCenterPoint.x+currentPoint.x, vc.view.center.y); + NSLog(@"center:%@",NSStringFromCGPoint(center)); + + offset = CGRectGetWidth(self.rightPanController.view.frame) - x; + CGAffineTransform transf = CGAffineTransformIdentity; + CGFloat percentValue = abs(currentPoint.x)/320.0; + CGFloat newAlphaValue = percentValue* kMaxBlackMaskAlpha; + BOOL rightPanIsShow = _rightPanViewCenterPoint.x==160; + newAlphaValue = rightPanIsShow?1-newAlphaValue:newAlphaValue; + CGFloat newTransformValueFRTL = 1-(1-kViewScaleSize)*percentValue; + CGFloat newTransformValueFLTR = kViewScaleSize+(1-kViewScaleSize)*percentValue; + + CGFloat newTransformValue = rightPanIsShow?newTransformValueFLTR:newTransformValueFRTL; + [self currentViewController].view.transform = CGAffineTransformScale(transf,newTransformValue,newTransformValue); + _blackMask.alpha = newAlphaValue; + + if(center.x<160) + { + vc.view.center = CGPointMake(160, vc.view.center.y); + [self currentViewController].view.userInteractionEnabled = YES; + return; } - return; + vc.view.center = center; + } - if(_rightPanViewProcessTouch) + if(_rightTouchProcess) { - vc = self.rightPanController; - NSLog(@"come on right pan controller"); - offset = CGRectGetWidth(vc.view.frame) - x; - vc.view.frame = [self getSlidingRectForOffset:offset]; - - if (panGesture.state == UIGestureRecognizerStateEnded || panGesture.state == UIGestureRecognizerStateCancelled) { + if (panGesture.state == UIGestureRecognizerStateEnded || + panGesture.state == UIGestureRecognizerStateCancelled){ + panDirection = moveLeft?PanDirectionLeft:PanDirectionRight; + _rightTouchProcess = NO; [self rightPanViewControllerAnimationEndWithDirection:panDirection]; } return; } + NSLog(@"enter origin process"); + _originTouchProcess = YES; offset = CGRectGetWidth(vc.view.frame) - x; NSLog(@"panOrigin.x:%f",_panOrigin.x); NSLog(@"x:%f",x); @@ -320,8 +358,8 @@ - (void) gestureRecognizerDidPan:(UIPanGestureRecognizer*)panGesture { _blackMask.alpha = newAlphaValue; - NSLog(@""); if (panGesture.state == UIGestureRecognizerStateEnded || panGesture.state == UIGestureRecognizerStateCancelled) { + _originTouchProcess = NO; [self completeSlidingAnimationWithDirection:panDirection]; } } From 75a846f4980177845d905ceffd853bdef3068ba5 Mon Sep 17 00:00:00 2001 From: Nicholas Tau Date: Sat, 8 Jun 2013 18:01:59 +0800 Subject: [PATCH 10/15] delete NSLog --- Classes/FlipBoardNavigationController.m | 7 ------- 1 file changed, 7 deletions(-) diff --git a/Classes/FlipBoardNavigationController.m b/Classes/FlipBoardNavigationController.m index 52f08b6..3783df4 100644 --- a/Classes/FlipBoardNavigationController.m +++ b/Classes/FlipBoardNavigationController.m @@ -295,7 +295,6 @@ - (void) gestureRecognizerDidPan:(UIPanGestureRecognizer*)panGesture { (!moveLeft&&_rightPanController.view.center.x<480))&&//向右推出rightPanView !_originTouchProcess)//当前是否正在处理原有的touch事件 { - NSLog(@"enter rightPan process"); if([self.view.subviews indexOfObject:self.currentViewController.view]> [self.view.subviews indexOfObject:_blackMask]) { @@ -306,7 +305,6 @@ - (void) gestureRecognizerDidPan:(UIPanGestureRecognizer*)panGesture { _rightTouchProcess = YES; vc = self.rightPanController; CGPoint center = CGPointMake(_rightPanViewCenterPoint.x+currentPoint.x, vc.view.center.y); - NSLog(@"center:%@",NSStringFromCGPoint(center)); offset = CGRectGetWidth(self.rightPanController.view.frame) - x; CGAffineTransform transf = CGAffineTransformIdentity; @@ -341,16 +339,11 @@ - (void) gestureRecognizerDidPan:(UIPanGestureRecognizer*)panGesture { } return; } - NSLog(@"enter origin process"); _originTouchProcess = YES; offset = CGRectGetWidth(vc.view.frame) - x; - NSLog(@"panOrigin.x:%f",_panOrigin.x); - NSLog(@"x:%f",x); - NSLog(@"offset:%f",offset); vc.view.frame = [self getSlidingRectForOffset:offset]; CGAffineTransform transf = CGAffineTransformIdentity; - NSLog(@"offset:%f",offset); CGFloat newTransformValue = 1 - (offset/(self.view.frame.size.width/10))/100; CGFloat newAlphaValue = (offset/self.view.frame.size.width)* kMaxBlackMaskAlpha; From 775a0501ed2027f56749663975cf588dd38823fd Mon Sep 17 00:00:00 2001 From: Nicholas Tau Date: Sat, 8 Jun 2013 18:02:17 +0800 Subject: [PATCH 11/15] add a tableview as childView to Test --- .../FlipViewControllerDemo/ViewController.m | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sample/FlipViewControllerDemo/FlipViewControllerDemo/ViewController.m b/Sample/FlipViewControllerDemo/FlipViewControllerDemo/ViewController.m index 8448cb3..5065b59 100644 --- a/Sample/FlipViewControllerDemo/FlipViewControllerDemo/ViewController.m +++ b/Sample/FlipViewControllerDemo/FlipViewControllerDemo/ViewController.m @@ -35,6 +35,9 @@ - (IBAction)push:(UIButton *)sender { UIViewController * controller = [[UIViewController alloc] init]; controller.view.backgroundColor = [UIColor purpleColor]; + + UITableView * tv = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 320, 400)]; + [controller.view addSubview:tv]; UIViewController * panController = [[UIViewController alloc] init]; panController.view.backgroundColor = [UIColor grayColor]; From 1604a2a6b82e65b65445f1a04f67adec26e50bbd Mon Sep 17 00:00:00 2001 From: Nicholas Tau Date: Sun, 9 Jun 2013 10:38:01 +0800 Subject: [PATCH 12/15] =?UTF-8?q?demon=20=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FlipViewControllerDemo/ViewController.m | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Sample/FlipViewControllerDemo/FlipViewControllerDemo/ViewController.m b/Sample/FlipViewControllerDemo/FlipViewControllerDemo/ViewController.m index 5065b59..3ae44ad 100644 --- a/Sample/FlipViewControllerDemo/FlipViewControllerDemo/ViewController.m +++ b/Sample/FlipViewControllerDemo/FlipViewControllerDemo/ViewController.m @@ -38,9 +38,13 @@ - (IBAction)push:(UIButton *)sender { UITableView * tv = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 320, 400)]; [controller.view addSubview:tv]; + UIViewController * panController = [[UIViewController alloc] init]; panController.view.backgroundColor = [UIColor grayColor]; + UITableView * tv1 = [[UITableView alloc] initWithFrame:CGRectMake(100, 0, 320, 400)]; + [panController.view addSubview:tv1]; + self.flipboardNavigationController.rightPanController =panController; [self.flipboardNavigationController pushViewController:controller]; From 44171bbbb13e10b6dbfa1b741d6e9c493fabeedb Mon Sep 17 00:00:00 2001 From: Nicholas Tau Date: Sun, 9 Jun 2013 11:22:21 +0800 Subject: [PATCH 13/15] =?UTF-8?q?=E5=88=86=E7=A6=BBtableView=E6=BB=9A?= =?UTF-8?q?=E5=8A=A8=E4=B8=8Epan=E6=89=8B=E5=8A=BF=E5=8A=A8=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Classes/FlipBoardNavigationController.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Classes/FlipBoardNavigationController.m b/Classes/FlipBoardNavigationController.m index 3783df4..3e29e4a 100644 --- a/Classes/FlipBoardNavigationController.m +++ b/Classes/FlipBoardNavigationController.m @@ -232,7 +232,7 @@ - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceive } - (BOOL) gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer { - return YES; + return NO; } -(void)rightPanViewControllerAnimationEndWithDirection:(PanDirection)direction From 7bcd848ad383d0a71ec44ff78f8f034ec48770ec Mon Sep 17 00:00:00 2001 From: Nicholas Tau Date: Mon, 17 Jun 2013 17:10:16 +0800 Subject: [PATCH 14/15] =?UTF-8?q?bug=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Classes/FlipBoardNavigationController.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Classes/FlipBoardNavigationController.m b/Classes/FlipBoardNavigationController.m index 3e29e4a..9db4869 100644 --- a/Classes/FlipBoardNavigationController.m +++ b/Classes/FlipBoardNavigationController.m @@ -288,7 +288,7 @@ - (void) gestureRecognizerDidPan:(UIPanGestureRecognizer*)panGesture { BOOL moveLeft = vel.x<1; UIViewController * vc= [self currentViewController]; - if(self.rightPanController.view.frame.origin.x==0&&moveLeft) + if(self.rightPanController&&self.rightPanController.view.frame.origin.x==0&&moveLeft) return; if(self.rightPanController&&//是否存在右侧的panViewController ((moveLeft&&_rightPanController.view.center.x>160)||//向左滑入rightPanView From 570363c5dbd4e0d30b1dd53048e2c2d6b07040a1 Mon Sep 17 00:00:00 2001 From: jack zhou <4686150@qq.com> Date: Tue, 2 Jul 2013 14:38:17 +0800 Subject: [PATCH 15/15] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20pop=E5=90=8E=20?= =?UTF-8?q?=E5=8F=AA=E9=87=8A=E6=94=BEcontroller=E4=B8=8D=E8=83=BD?= =?UTF-8?q?=E9=87=8A=E6=94=BEview=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Classes/FlipBoardNavigationController.m | 1 + 1 file changed, 1 insertion(+) diff --git a/Classes/FlipBoardNavigationController.m b/Classes/FlipBoardNavigationController.m index 3783df4..f17f6f8 100644 --- a/Classes/FlipBoardNavigationController.m +++ b/Classes/FlipBoardNavigationController.m @@ -125,6 +125,7 @@ - (void) popViewControllerWithCompletion:(FlipBoardNavigationControllerCompletio [self.view bringSubviewToFront:[self previousViewController].view]; [currentVC removeFromParentViewController]; [currentVC didMoveToParentViewController:nil]; + [currentVC.view removeFromSuperview];///修正view不能释放 jack 2013-7-2 [self.viewControllers removeObject:currentVC]; _animationInProgress = NO; handler();