1
votes

I'v been using UINavigationController together with UITableView controllers to implement hierarchical navigation on my app.

Unfortunately the UI is in Hebrew so everything have to be from right to left to make sense.

The real problem is the navigation controller, slides animation direction and the back button position.

I haven't found any elegant solution so far, had some limited success with overriding the pop and push methods creating transition between the views as suggested here: How to change the Push and Pop animations in a navigation based app

But it's a very limited solution and it doesn't look right.

Do you have any suggestions? Do I really have to rewrite/replicate the navigation controller with something new? If so would you suggest inheriting UINavigationController or UIViewController ?

2

2 Answers

1
votes

If you're willing to put a little work into it, you could use a replacement for the UINavigationController such as the FJTransitionController https://github.com/coreyfloyd/FJSTransitionController. It functions as a drop-in, customizable replacement for navigation or tab controllers as well as any other navigation behavior you could want. You will need to provide the UI on your own though, the existing UINavigationBar might be usable.

0
votes

Here's a very sneaky approach that I coded this weekend for use in my app. Put this code in the active view controller (i.e. the table view) that wants to pseudo-"push" a new view controller with the right to left transition. Prepare the new ViewController and then call this. The only thing slightly different from the standard left to right transition is that the title bar does not animate, it swaps out after. You "borrow" the new view controller and make it a child of the active view controller long enough to do the animation, then put things back as they should be. Apple is very specific about UINavigationController rules, and virtually any change to the order here or the pushing and popping logic throws an exception, so there was a fair amount of trial and error.

-(void) showVC:(UIViewController *) nextVC rightToLeft:(BOOL) rightToLeft {
    [self addChildViewController:neighbor];
    CGRect offscreenFrame = self.view.frame;
    if(rightToLeft) {
        offscreenFrame.origin.x = offscreenFrame.size.width * -1.0;
    } else if(direction == MyClimbDirectionRight) {
        offscreenFrame.origin.x = offscreenFrame.size.width;
    }
    [[neighbor view] setFrame:offscreenFrame];
    [self.view addSubview:[neighbor view]];
    [neighbor didMoveToParentViewController:self];
    [UIView animateWithDuration:0.5 animations:^{
        [[neighbor view] setFrame:self.view.frame];
    } completion:^(BOOL finished){
        [neighbor willMoveToParentViewController:nil];
        [neighbor.view removeFromSuperview];
        [neighbor removeFromParentViewController];
        [[self navigationController] pushViewController:neighbor animated:NO];
        NSMutableArray *newStack = [[[self navigationController] viewControllers] mutableCopy];
        [newStack removeObjectAtIndex:1]; //self, just below top
        [[self navigationController] setViewControllers:newStack];
    }];
}