Skip to content

Commit

Permalink
Add a new method to pop the last Page
Browse files Browse the repository at this point in the history
Correction of setRootViewController animated from the commit of AppUnite
Bug correction on popPageAtIndex
  • Loading branch information
ipodishima committed Nov 9, 2011
1 parent 77124ce commit 766f39e
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@
*/
- (UIViewController*) firstVisibleViewController;

/*
Pop the last page*/
- (void) popLastPageAnimated:(BOOL) animated;

@end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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 {

Expand Down
24 changes: 21 additions & 3 deletions src/Cascade/CLCascadeNavigationController/CLCascadeView.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 766f39e

Please sign in to comment.