在UINavigationController中支持纵向和横向视图的最佳实践

在UINavigationController中支持纵向和横向视图的最佳实践

问题描述:

我搜寻了很多东西,但我不确定我想出的是解决这个问题的最好方法(尽管这似乎是唯一的方法).

I searched high and low and I'm not sure what I came out with is the best way of dealing with this (though it seems the only one).

根据要在不同的情况下使用多尖嘴iphone界面方向我实现了相关方法,并且一切似乎都正常进行.不幸的是,我必须处理UINavigationController,并且每个页面必须同时支持纵向和横向模式,并在两种模式下都再现相同的功能.这意味着,如果某个用户决定从纵向切换为横向,则整个应用程序应允许他以自己选择的模式来回浏览页面.

According to Want to use muliple nibs for different iphone interface orientations I implemented the relevant methods, and everything seems to work fine. Unfortunately I have to deal with a UINavigationController, and each page has to support both portrait and landscape modes, and reproduce the same functionalities in both modes. That means that If a user at some point decides to switch from portrait to landscape, the whole app should allow him to navigate back and forth through the pages in the mode he chose.

很显然,缺少的文档是如何处理的.在我看来,我有许多按钮,带有执行导航的附加showChild方法.所有人都可以在人像模式下正常工作(据我所知,这是默认模式).方法如下:

Apparently the bit of documentation that's missing is how to deal with this. In my views I have a number of buttons with an attached showChild method that performs the navigation. All works well in portrait mode (that is the default mode, as far as I understand). The method goes like this:

- (IBAction)showChild:(UITapGestureRecognizer *)sender {
    UIView *view = [sender view];
    PortraitViewController *nextPortraitViewcontroller = [[PortraitViewController alloc] initWithNibName:@"Portrait" bundle:nil];
    [self.navigationController pushViewController:nextPortraitViewcontroller animated:YES];
}

但是在横向模式下,我得到的结果好坏参半. LandscapeViewController类中的showChild:方法完全相同,它从PortraitViewController开始构建一个视图,并将其推送到导航控制器.一切似乎都进行得很好,但是当我向后浏览时,我得到的是先前显示的PortraitViewController,而不是风景,而且其子视图都散布在周围,而不是放在我放置它们的位置.

But when it comes to the landscape mode I get mixed results. The showChild: method in the LandscapeViewController class is exactly the same, it builds a view starting from the PortraitViewController and pushes it to the navigation controller. It all seems to go well but when I navigate back I get the previous PortraitViewController shown, not the landscape, and also its subviews are all spread around, not where I put them.

现在的问题是:由于Apple似乎并不真正在乎文档和最佳实践(afaik,整个机制远非理想,我可以说这来自于人机交互设计和编程的背景) )什么是正确的-Apple的处理方式?

Now the question is: since Apple doesn't really seem to care about documentation and best practices (afaik this whole mechanism is very far from ideal, and I can say this coming from a background of human-computer interaction design and programming) what's the correc--Apple way of doing this?

我设置了一个示例项目来演示如何解决"我的问题.这可能不是唯一的方法,也不是最好的方法,但是由于文档不足或缺乏,这是我想出的最好方法.

I set up a sample project to demonstrate how I "solved" my problem. It's probably not the only way, nor the best way, but due to documentation, or lack thereof, this is the best I came up with.

https://github.com/Morpheu5/Rotation