Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ build
Breakpoints.xcbkptlist
Cascade.xcscheme
CLCascade.xcscheme
xcschememanagement.plist
xcschememanagement.plist
.svn
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
CLCascadeView* _cascadeView;
}

@property (nonatomic, strong, readonly) CLCascadeView* cascadeView;

/*
List of CLViewControllers on stock.
*/
Expand All @@ -45,6 +47,7 @@
* If sender is not last, then controller pop next controller and push new view from sender
*/
- (void) addViewController:(CLViewController*)viewController sender:(CLViewController*)sender animated:(BOOL)animated;
- (void) popPagesFromLastIndexTo:(NSInteger)toIndex;

/*
First in hierarchy CascadeViewController (opposite to lastCascadeViewController)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
#import "CLViewController.h"
#import "CLSegmentedView.h"

//#define NSDebugLog( ... ) NSLog( __VA_ARGS__ )
#define NSDebugLog( ... )

@interface CLCascadeNavigationController (Private)
- (void) addPagesRoundedCorners;
- (void) addRoundedCorner:(UIRectCorner)rectCorner toPageAtIndex:(NSInteger)index;
Expand All @@ -23,14 +26,6 @@ @implementation CLCascadeNavigationController
@synthesize viewControllers = _viewControllers;
@synthesize leftInset, widerLeftInset;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}

- (void)dealloc
{
Expand All @@ -48,6 +43,11 @@ - (void)didReceiveMemoryWarning

#pragma mark - View lifecycle

- (CLCascadeView*)cascadeView
{
return _cascadeView;
}

- (void)viewDidLoad
{
[super viewDidLoad];
Expand Down Expand Up @@ -77,8 +77,48 @@ - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interface
return YES;
}

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration {
[_cascadeView updateContentLayoutToInterfaceOrientation:interfaceOrientation duration:duration];
-(void)willRotateToInterfaceOrientation:( UIInterfaceOrientation )toInterfaceOrientation_
duration:( NSTimeInterval )duration_
{
//dodikk - blocks are available since iOS4
[ self.viewControllers enumerateObjectsUsingBlock: ^void(id obj_, NSUInteger idx_, BOOL *stop_)
{
UIViewController* controller_ = (UIViewController*)obj_;
[ controller_ willRotateToInterfaceOrientation: toInterfaceOrientation_
duration: duration_ ];

*stop_ = NO;
} ];
}

-(void)didRotateFromInterfaceOrientation:( UIInterfaceOrientation )fromInterfaceOrientation_
{
//dodikk - blocks are available since iOS4
[ self.viewControllers enumerateObjectsUsingBlock: ^void(id obj_, NSUInteger idx_, BOOL *stop_)
{
UIViewController* controller_ = (UIViewController*)obj_;
[ controller_ didRotateFromInterfaceOrientation: fromInterfaceOrientation_ ];

*stop_ = NO;
} ];
}

- (void)willAnimateRotationToInterfaceOrientation:( UIInterfaceOrientation )interfaceOrientation_
duration:( NSTimeInterval )duration_
{
//dodikk - blocks are available since iOS4
[ self.viewControllers enumerateObjectsUsingBlock: ^void(id obj_, NSUInteger idx_, BOOL *stop_)
{
UIViewController* controller_ = (UIViewController*)obj_;
[ controller_ willAnimateRotationToInterfaceOrientation: interfaceOrientation_
duration: duration_ ];

*stop_ = NO;
} ];


[_cascadeView updateContentLayoutToInterfaceOrientation: interfaceOrientation_
duration: duration_ ];
}


Expand Down Expand Up @@ -189,7 +229,7 @@ - (void) cascadeView:(CLCascadeView*)cascadeView pageDidDisappearAtIndex:(NSInte
if (index > [_viewControllers count] - 1) return;

UIViewController<CLViewControllerDelegate>* controller = [_viewControllers objectAtIndex: index];
if ([controller respondsToSelector:@selector(pageDidAppear)]) {
if ([controller respondsToSelector:@selector(pageDidDisappear)]) {
[controller pageDidDisappear];
}

Expand Down Expand Up @@ -244,39 +284,63 @@ - (void) setRootViewController:(CLViewController*)viewController animated:(BOOL)
}

///////////////////////////////////////////////////////////////////////////////////////////////////
- (void) addViewController:(CLViewController*)viewController sender:(CLViewController*)sender animated:(BOOL)animated {

// if in not sent from categoirs view
if (sender) {

// get index of sender
NSInteger indexOfSender = [_viewControllers indexOfObject:sender];

// if sender is not last view controller
if (indexOfSender != [_viewControllers count] - 1) {

// pop views and remove from _viewControllers
[self popPagesFromLastIndexTo:indexOfSender];
}
}

// set cascade navigator to view controller
[viewController setCascadeNavigationController: self];
// add controller to array
[self.viewControllers addObject: viewController];

#if __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_5_0
[self addChildViewController:viewController];
#endif

// push view
[_cascadeView pushPage:[viewController view]
fromPage:[sender view]
animated:animated];

#if __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_5_0
[viewController didMoveToParentViewController:self];
#endif
-(void)addViewController:(CLViewController*)viewController
sender:(CLViewController*)sender
animated:(BOOL)animated
{
// if in not sent from categoirs view
if (sender)
{
// get index of sender
NSInteger indexOfSender = [_viewControllers indexOfObject:sender];

// if sender is not last view controller
if (indexOfSender != [_viewControllers count] - 1)
{
// pop views and remove from _viewControllers
[self popPagesFromLastIndexTo:indexOfSender];
}
}

UIView* sender_view_ = [ sender view ];
UIView* view_to_push_ = [ viewController view ];

NSDebugLog
(
@"CLCascadeNavigationController->addViewController: %@"
@"\n \t\t\t " @"sender: %@"
@"\n \t\t\t " @"animated: %d"
@"\n"
@"\n \t\t\t " @"self->_cascadeView: %@"
@"\n \t\t\t " @"sender->view: %@"
@"\n \t\t\t " @"viewController->view: %@"
, viewController
, sender
, animated
, _cascadeView
, sender_view_
, view_to_push_
);

// set cascade navigator to view controller
[viewController setCascadeNavigationController: self];
// add controller to array
[self.viewControllers addObject: viewController];

{
#if __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_5_0
[self addChildViewController:viewController];
#endif

// push view
[ _cascadeView pushPage: view_to_push_
fromPage: sender_view_
animated: animated ];

#if __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_5_0
[viewController didMoveToParentViewController:self];
#endif
}
}

///////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -350,16 +414,32 @@ - (void) addPagesRoundedCorners {


///////////////////////////////////////////////////////////////////////////////////////////////////
- (void) popPagesFromLastIndexTo:(NSInteger)toIndex {
if (toIndex < 0) toIndex = 0;
-(void)popPagesFromLastIndexTo:(NSInteger)toIndex
{
NSUInteger view_controllers_count_ = [_viewControllers count];
if ( 0 == view_controllers_count_ )
{
return;
}

if (toIndex < 0)
{
toIndex = 0;
}

// index of last page
NSUInteger index = [_viewControllers count] - 1;
NSUInteger index = view_controllers_count_ - 1;
// pop page from back
NSEnumerator* enumerator = [_viewControllers reverseObjectEnumerator];
// enumarate pages
while ([enumerator nextObject] && _viewControllers.count > toIndex+1) {

while ([enumerator nextObject] && _viewControllers.count > toIndex+1)
{
if ( ![ _cascadeView canPopPageAtIndex: index ] )
{
//dodikk - maybe break fits better
continue;
}

#if __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_5_0
UIViewController* viewController = [_viewControllers objectAtIndex:index];
[viewController willMoveToParentViewController:nil];
Expand Down
4 changes: 3 additions & 1 deletion src/Cascade/CLCascadeNavigationController/CLCascadeView.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@

- (void) pushPage:(UIView*)newPage fromPage:(UIView*)fromPage animated:(BOOL)animated;

- (void) popPageAtIndex:(NSInteger)index animated:(BOOL)animated;
-(void)popPageAtIndex:(NSInteger)index animated:(BOOL)animated;
-(BOOL)canPopPageAtIndex:(NSInteger)index;

- (void) popAllPagesAnimated:(BOOL)animated;

- (UIView*) loadPageAtIndex:(NSInteger)index;
Expand Down
Loading