FRLayeredNavigationController
FRLayeredNavigationController copied to clipboard
Specify minimum width for child view controllers
FRLayeredNavigationController does not work well as master view controller in master-detail application (UISplitviewController), as shown in this screenshot http://imageshack.us/photo/my-images/543/photosl.png/
This could be improved by implementing a minimum width for child view controllers. If pushing new view controller would leave the new controller less room than what the minimum width is, all the view controllers on the stack would be moved left. In other words, instead of showing a constant width slice of each view controller in the stack, this the width of these slices should dynamically adjust to make room for more controllers.
This code (kind of) does what I would like to achieve. It should be called after pushing or popping view controllers. This is not a perfect solution, but something that worked for a prototype.
-(void) _adjustLayeredNavigationControllerLayerWidths{ NSInteger maxOverLap = 64; NSInteger maxSpaceForLayers = 128; NSInteger numberOfLayers = [self.layeredNavigationController.viewControllers count]-1;
if(numberOfLayers==0) return;
CGFloat nextItemDistance = MIN(maxOverLap, maxSpaceForLayers/(CGFloat) numberOfLayers);
CGFloat x=0;
for(UIViewController* viewController in self.layeredNavigationController.viewControllers){
viewController.layeredNavigationItem.nextItemDistance = nextItemDistance;
viewController.layeredNavigationItem.currentViewPosition = CGPointMake(x, viewController.layeredNavigationItem.currentViewPosition.y);
viewController.layeredNavigationItem.initialViewPosition = CGPointMake(x, viewController.layeredNavigationItem.initialViewPosition.y);
x=x+nextItemDistance;
}
[self.layeredNavigationController doLayout];
}