Best practice to support portrait and landscape views in a UINavigationController

余生颓废 提交于 2019-12-12 11:01:12

问题


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).

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.

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

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.

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?


回答1:


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



来源:https://stackoverflow.com/questions/6216920/best-practice-to-support-portrait-and-landscape-views-in-a-uinavigationcontrolle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!