UINavigationController and alternate landscape

In my application, I use an alternative landscape interface strategy (presenting your landscape as modal). I also use the navigation controller to navigate, and this causes the following problem: I don't know how to press / pop up correctly from landscape orientation.

I came up with the following solution, but someone might know the best. Suppose you only need to deal with two views. Let them be called AP, AL, BP, BL, where the second letter indicates the orientation. We start with a navigation controller with an AP inside. To switch between AP and BP, we just press / pop. To move from AP to AL, we present a trendy navigation controller with AL inside. To switch between AL and BL, we press / pop up in the second navigation controller. Now, to move from BP to BL, we pop without animation and present a modal navigation controller with BL sitting on top of AL. To switch from BL to BP, we fire the navigation control module and press BP without animation.

It seems a little ugly, but not so bad. Can anyone think of something better?

Thanks in advance!

+4
source share
1 answer

Is there any reason why you need to present your landscape orientation as modal in a separate controller? When I have two completely different views on my portrait and landscape orientations, I disappear between them when they are stretched during rotation.

This allows you to significantly distinguish between content in both orientations, a good transition between them and common code under one controller.

Here is the code. When the orientation changes, our UIViewController will switch between PortraitView and LandscapeView .

portraitView and landscape Note are children of the UIViewController view . The hierarchy is as follows:

UIViewController | - view | |- portraitView | |- landscapeView 

Both have their autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight so that they stretch as the view adjuster rotates.

 - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { if( orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight ) { [UIView animateWithDuration:duration animations:^ { //Fade the landscape view over the top of the //portrait view as during rotation landscapeView.alpha = 1.0f; } completion:^(BOOL finished) { //Hide the portrait view when landscape is fully //visible portraitView.alpha = 0.0f }]; } else { //Show the portrait view (underneath the landscape view) portraitView.alpha = 1.0f; [UIView animateWithDuration:duration animations:^ { //Fade out the landscape view to reveal the portrait view landscapeView.alpha = 0.0f; }]; } } 

Your controls and sub-items will disappear and be deactivated along with the corresponding views, allowing you to have completely different content. I used this recently to fade between two different background images when changing orientation. The effect is very smooth.

Now you can create your own two view controllers, A and B , which control the two views, as described above. Then you can simply click on the view controllers as usual and not worry about controlling the stack of the UINavigationController view controller during rotation.

+1
source

All Articles