从右到左UINavigationController

时间:2011-12-11 23:21:31

标签: iphone ios uinavigationcontroller uikit

我一直在使用UINavigationController和UITableView控制器在我的应用上实现分层导航。

不幸的是,UI是希伯来语,所以一切都必须从右到左才有意义。

真正的问题是导航控制器,幻灯片动画方向和后退按钮位置。

到目前为止,我还没有找到任何优雅的解决方案,在覆盖pop和push方法方面取得了一些有限的成功,如下所示: How to change the Push and Pop animations in a navigation based app

但这是一个非常有限的解决方案,看起来并不正确。

你有什么建议吗? 我是否真的必须用新的东西重写/复制导航控制器? 如果是这样,你会建议继承UINavigationController或UIViewController吗?

2 个答案:

答案 0 :(得分:1)

如果您愿意为此付出一些代价,可以使用UINavigationController的替代品,例如FJTransitionController https://github.com/coreyfloyd/FJSTransitionController。它可用作导航或标签控制器的插入式,可自定义替代品以及您可能需要的任何其他导航行为。您需要自己提供UI,但现有的UINavigationBar可能是可用的。

答案 1 :(得分:0)

这是一个非常偷偷摸摸的方法,我在本周末编写,用于我的应用程序。将此代码放在活动视图控制器(即表视图)中,该控制器希望伪造“推”具有从右到左转换的新视图控制器。准备新的ViewController,然后调用它。 唯一与标准从左到右过渡略有不同的是标题栏没有动画,它在之后交换。 您“借用”新的视图控制器并使其成为活动视图控制器的子项足够长的时间来执行动画,然后将它们放回原处。 Apple对UINavigationController规则非常具体,几乎任何对此处订单的更改或者推送和弹出逻辑都会引发异常,因此存在大量的反复试验。

-(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];
    }];
}