I have a UINavigationController-based app that only supports portrait, but need to push one view that requires landscape. I've found a previous post that describes how to allow mixed rotations for a single view, but what is the process for forcing a single view, when pushed, to be in landscape then returning the app to portrait mode when the view is popped.
Thanks!
You cannot force an orientation change just by pushing onto the nav stack. What you can do instead is present the view controller which must be landscape as a modal view controller instead.
Related
I'm trying to work with the iOS6 Auto-rotation mess.
I've looked at almost every single SO question relating to it, and no matter what I try, I can't get rotation working how I need it.
The app is using storyboards, and the layout is as follows:
Navigation controller ---> Root view controller ---> Tab view controller ---> View controller ---> Landscape view controller.
The view controller auto-rotates when I rotate the simulator, but when segueing back to the previous view (that is set to portrait), the view becomes landscape, when it should be portrait. If I rotate the simulator back, the view auto-rotates to portrait again, but this should've been done automatically!
I've implemented (UIInterfaceOrientation)preferredInterfaceOrientationForPresentationand it doesn't get called in any view controller I put it in.
I've subclassed the NavigationController to return the topViewController's shouldAutoRotate, supportedInterfaceOrientations and preferredInterfaceOrientationForPresentation and auto-rotation when rotating the simulator seems to work, but preferredInterfaceOrientationForPresentation never does its job.
Does anyone have a solution to this?
It would appear Apple have removed the ability to push a view in a specific orientation. preferredInterfaceOrientationForPresentation does get called, but only when popping back or presenting a view controller. I had to present my landscape view rather than push it, and set shouldAutoRotate = NO.
Refer to: In iOS6, trouble forcing ViewController to certain interfaceOrientation when pushed on stack for more details.
I have a UIPageViewController with a view controllers called UIZoomedImageViewController. The UIZoomedImageViewController has different layout/positioning depending whether it's portrait or landscape. I have a method called setViewBasedOnOrientation that is called on willAnimateToInterfaceOrientation.
The issue I am having now however is that when I rotate the device and swipe to the next view controller it still has the size/layout of the previous orientation. How do I deal with this?
I am making a navigation based app and I need only portrait orientation except in a ZoomPictureViewController ( Zoom in, zoom out images) that supports all orientations.
I am presenting ZoomPictureViewController and returning YES in shouldAutorotateToInterfaceOrientation:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return YES;
}
But I get no rotation. I know that shouldAutorotateToInterfaceOrientation, willRotateToInterfaceOrientation, RotateToInterfaceOrientation are only get called on the current/visible view controller but this is not happening in my case. I have checked it via putting breakpoints and NSLog.
Are you using any type of Navigation Controller or a Tab View Controller? I've noticed that there are issues when rotating a UIView that's not the first or only view as a direct child of the main window.
So if your UIView is part of a Navigation Controller or a Tab View Controller, you'll also need to override shouldAutoRotateToInterfaceOrientation on the Navigation Controller or Tab View Controller.
Also I here's an important gotcha in the Apple documentation that might explain the problem you are having.
Tab bar controllers support a portrait
orientation by default and do not
rotate to a landscape orientation
unless all of the root view
controllers support such an
orientation. When a device orientation
change occurs, the tab bar controller
queries its array of view controllers.
If any one of them does not support
the orientation, the tab bar
controller does not change its
orientation.
I have an OpenGL app which supports dynamic device orientation. I can rotate the device to any of the 4 physical orientations and everything works as expected.
Now I've added a modal view controller so that you can get a settings view (this is non-OpenGL). The modal view controller also supports any device orientation.
However, if I present the modal view controller in orientation A (e.g. portrait) and dismiss it in orientation B (e.g. landscape-right), after it is dimissed, the OpenGL view is corrupted (the aspect ratio looks wrong). I have to orient the device to a different orientation for the OpenGL view to 'correct' itself.
When the modal view controller is dismissed, it's like the app thinks that it's already in orientation B, so it doesn't ever rotate the OpenGL view.
If I disable rotation on the modal view controller, then if I present the modal controller in orientation A, rotate the device to orientation B (the modal view controller no longer rotates) and dismiss the controller, the OpenGL view gets willRotateToInterfaceOrientation/didRotateFromInterfaceOrientation and correctly orients to orientation B.
Is there any way to preserve the dynamic orientation of the modal controller, yet have the OpenGL view also properly rotate after the modal controller is dismissed?
Thank you.
I had a similar issue with a custom action sheet, and decided that the simplest answer would be to temporarily disallow rotation while the view is presented. You can see an example of this in the Apple Notes app, whenever an action sheet is presented the orientation becomes locked.
I know you've already tried this and it works, I just think you should consider that as a valid solution.
I'm not sure how to solve it otherwise, you would probably need to store any changes in orientation in your modal view controller and pass them back to the OpenGL view controller, either at the same time or once at the point of dismissing the settings view, then manually re-render.
(By the way I develop without Interface Builder)
If you have a tab bar app that autorotates, so all the autoresizing masks are set, how do you make it work with all the views? Like if one view autorotates to landscape, you select a different tab in the tab bar, and the view associated with that tab comes up, and its all messed because it never got autorotated, it got initialized with the frame that makes it fit in portrait mode, even though the autoresizingmasks are set to have it look fine in landscape, it never got rotated. Whats the solution? (By the way, I'm lazy loading the views, so the only view loaded at any given time is the view(view controller's view) associated with the selected tab).
Does declaring all the required orientations in the didrotatefrominterfaceorientation method in every view controller you are using fix the problem?
e.g. your main view, with the tab bar is called "mainView", and when you choose a tab, it loads a view called "firstView", does the "firstView" view controller have the orientations set?
If a view controller is not loaded, it won't be able to respond to autorotation messages. So in your view controller, when it's loaded from the nib, it should check the orientation and resize and move things as necessary.