From 766f39e990000d03048b7b5237d0a5485f45ae0d Mon Sep 17 00:00:00 2001 From: ipodishima Date: Wed, 9 Nov 2011 09:58:59 +0100 Subject: [PATCH] Add a new method to pop the last Page Correction of setRootViewController animated from the commit of AppUnite Bug correction on popPageAtIndex --- .../CLCascadeNavigationController.h | 3 ++ .../CLCascadeNavigationController.m | 30 ++++++++++++------- .../CLCascadeView.m | 24 +++++++++++++-- 3 files changed, 44 insertions(+), 13 deletions(-) diff --git a/src/Cascade/CLCascadeNavigationController/CLCascadeNavigationController.h b/src/Cascade/CLCascadeNavigationController/CLCascadeNavigationController.h index 6848df1..c5a9489 100644 --- a/src/Cascade/CLCascadeNavigationController/CLCascadeNavigationController.h +++ b/src/Cascade/CLCascadeNavigationController/CLCascadeNavigationController.h @@ -63,6 +63,9 @@ */ - (UIViewController*) firstVisibleViewController; +/* + Pop the last page*/ +- (void) popLastPageAnimated:(BOOL) animated; @end diff --git a/src/Cascade/CLCascadeNavigationController/CLCascadeNavigationController.m b/src/Cascade/CLCascadeNavigationController/CLCascadeNavigationController.m index 7b5055e..d147e96 100644 --- a/src/Cascade/CLCascadeNavigationController/CLCascadeNavigationController.m +++ b/src/Cascade/CLCascadeNavigationController/CLCascadeNavigationController.m @@ -239,7 +239,7 @@ - (void) cascadeViewDidCancelPullToDetachPages:(CLCascadeView*)cascadeView { /////////////////////////////////////////////////////////////////////////////////////////////////// - (void) setRootViewController:(UIViewController*)viewController animated:(BOOL)animated { // pop all pages - [_cascadeView popAllPagesAnimated: animated]; + [_cascadeView popAllPagesAnimated: NO]; // remove all controllers [self removeAllPageViewControllers]; // add root view controller @@ -348,7 +348,7 @@ - (void) addPagesRoundedCorners { /////////////////////////////////////////////////////////////////////////////////////////////////// -- (void) popPagesFromLastIndexTo:(NSInteger)toIndex { +- (void) popPagesFromLastIndexTo:(NSInteger)toIndex animated:(BOOL)animated { if (toIndex < 0) toIndex = 0; // index of last page @@ -357,25 +357,35 @@ - (void) popPagesFromLastIndexTo:(NSInteger)toIndex { NSEnumerator* enumerator = [_viewControllers reverseObjectEnumerator]; // enumarate pages while ([enumerator nextObject] && _viewControllers.count > toIndex+1) { - - #if __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_5_0 + +#if __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_5_0 UIViewController* viewController = [_viewControllers objectAtIndex:index]; [viewController willMoveToParentViewController:nil]; - #endif - +#endif + // pop page at index - [_cascadeView popPageAtIndex:index animated:NO]; + [_cascadeView popPageAtIndex:index animated:animated]; [_viewControllers removeLastObject]; - - #if __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_5_0 + +#if __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_5_0 [viewController removeFromParentViewController]; - #endif +#endif index--; } } +/////////////////////////////////////////////////////////////////////////////////////////////////// +- (void) popPagesFromLastIndexTo:(NSInteger)toIndex { + [self popPagesFromLastIndexTo:toIndex animated:NO]; +} + +/////////////////////////////////////////////////////////////////////////////////////////////////// +- (void) popLastPageAnimated:(BOOL) animated { + [self popPagesFromLastIndexTo:[_viewControllers count] - 2 animated:animated]; +} + /////////////////////////////////////////////////////////////////////////////////////////////////// - (void) removeAllPageViewControllers { diff --git a/src/Cascade/CLCascadeNavigationController/CLCascadeView.m b/src/Cascade/CLCascadeNavigationController/CLCascadeView.m index 5bb154b..6b2c37a 100644 --- a/src/Cascade/CLCascadeNavigationController/CLCascadeView.m +++ b/src/Cascade/CLCascadeNavigationController/CLCascadeView.m @@ -159,8 +159,26 @@ - (void) pushPage:(UIViewController*)newPageController fromPage:(UIViewControlle frame.origin.x = 0.0f; } - // set new page frame - [newPage setFrame: frame]; + // animation, from left to right + + if (animated && (fromPage == nil) && (([_scrollView contentOffset].x >= 0))) { + + // start frame animation + CGRect startRect = CGRectMake(origin.x - size.width, origin.y, size.width, size.height); + // set new page fram + [newPage setFrame: startRect]; + + // animation + [UIView animateWithDuration:0.15 + animations: ^{ + // set new page frame aimate + [newPage setFrame: frame]; + + }]; + } else { + // set new page frame + [newPage setFrame: frame]; + } // add page to array of pages [_pages addObject: newPageController]; // update content size @@ -223,7 +241,7 @@ - (void) popPageAtIndex:(NSInteger)index animated:(BOOL)animated { // animate pop [UIView animateWithDuration:0.4f animations:^ { - [item setAlpha: 0.0f]; + [((UIViewController*)item).view setAlpha: 0.0f]; } completion:^(BOOL finished) { // unload and remove page