This is the easiest way to explain it, keep in mind the view is nested in a Navigation Controller:
1.) App launches and whatever the orientation the device is in, the App is in portrait orientation no matter what. I have the shouldRotate method returning no, so it never rotates.
2.) I click a button, go to another view and turn it to landscape orientation (which is fine)
3.) While in landscape orientation in another view, I hit the "Back" button on the Navigation Controller and it returns me to the view controller I DON'T want rotated in landscape orientation.
What is a good way to consistently keep my main view controller in portrait orientation while coming from a view controller in landscape orientation?
Thanks!
If your design allows it you might want to simply hide the back button until the app is rotated back to portrait. This would force them to be in the orientation you need when they navigate back.
Related
I have an application which has a Tab Bar Controller with two items in it. Each item has its own Navigation Controller. Each part of the application has different behaviors. So I am not able to control the device orientation app-wide. However, in the second part of the app, I mean in the second navigation controller, the behavior should be slightly different.
I have a parent view controller in the second navigation controller. It should be always portrait. So I have made it using a lock method from the answer: https://stackoverflow.com/a/41811798/2152616
Basically, I call lock methods and it works fine. It also pushes to another view controller on some user action. The second view controller does not need to support landscape. So I am able to use the same technique to lock the orientation to portrait. However, when user rotate the device to landscape the I should present another view controller. In the case I lock the orientation, I'm not able to detect the orientation change.
How can I detect the orientation while the view controller supports only portrait mode?
I have a very simple test iOS8 application that uses two UIWindows. The first window is only allowed to be displayed in portrait mode. When shown, the second window allows AllButUpsideDown.
The button in the first window can be used to show the second window...
The second window supports landscape mode as shown below...
If the second window is dismissed (removed) while in landscape, the first window now looks
like below..
Why is the status bar in left in the landscape position? Also, I noticed the [UIScreen mainScreen].bounds are landscape size?
(Setting the status bar orientation does nothing)
Any help would be greatly appreciated, thanks.
I found the solution and thought I'd share..
To force the orientation to change you have to 'present' a view controller that has its preferredInterfaceOrientationForPresentation method set to the orientation you want. So, in the above case the main window's root view controller can present/dismiss a blank view controller with its preferred orientation set to portrait.
When you click on the right part of the "window 2", what happen ? If you look at the point clicked, do you have the right coordinates ?
I'm trying to get navigation between views that support landscape or portrait orientations working using a navigation controller and pushViewController (and IOS6+ code) and have a problem where after pushing a landscape view controller onto the navigation controller stack, the view controller view correctly is in landscape but the device is still in portrait orientation. (imagine an arrow pointing left to right on a landscape screen, here it points from down to up on a portrait screen so the dimensions are correct - it's just the device should be in landscape mode so the arrow points left to right - if that makes sense)
I have a portraitViewController and landscapeViewController that my different sub modes use.
Using the iOS 6 method, The two classes overload
-(BOOL)shouldAutorotate;
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation;
-(NSUInteger) supportedInterfaceOrientations;
appropriately.
I also have my own derived navigationcontroller that overrrides:
-(BOOL)shouldAutorotate;
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation;
-(NSUInteger) supportedInterfaceOrientations;
with the functions returning the same functions of the top view controller (so we're not bound to portrait mode by the top level view controller).
My first problem is that the device doesn't do an orientation refresh when you use pushViewController onto the navigation controller. This is well documented and has been solved up to now by using dismissViewController and presentViewController which forces a device orientation refresh which in turn queries the new view controller about what orientations it supports and switches the device appropriately.
This works but loses transitioning between view controllers (i.e with the new view sliding in from the right of the screen) as the previous view is removed from screen before the next is added and the newly presented view is applied to the entire screen directly.
Because of this, I've been trying to get things working using pushViewController rather than present / dismissViewController. pushViewController works fine when I navigate from portrait to portrait view - the new view slides in nicely - it's when I switch from a portrait to landscape view controller than things break.
Just pushViewController doesn't cause the device to refresh it's orientation and query what the new view would like to use. I've added calls to present / dismissModalViewController before my call to pushViewcontroller to force an orientation check with the new view controller.
* the problem *
This doesn't work however because the view is now in landscape mode but the device is still in portrait mode so the view is at 90 degs to what it should be.
I've tried fixing this by setting the status bar orientation to match the view controller landscape orientation but this causes massive problems when the user manually rotates the device from then on as they aren't in sync. Also in iOS 6, you can't do that if your view controller returns YES from shouldAutoRotate function (calls to setStausBarOrientation are ignored if you control orientation yourself in your view controller) so it took a large hack to do it and it just doesn't feel like the right solution.
To summarise, how can I use a navigation controller & pushViewController (using iOS6) and switch between landscape and portrait views properly? At the moment, I can't get the device to update along with the view so the interface is in landscape but the device is still in portrait. If I try using setStatusBarOrientation to force the device to landscape, things start to go wrong as soon as I manually rotate the screen and it requires such a hack it just can't be the right answer.
thanks!
:-)
I currently have an authentication view controller defined as the rootViewController when the app starts. When the user is authenticated, the authentication view controller changes the rootViewController of the main windows to a split view controller.
My problem is when I happen to be in landscape mode and that it switches views, the split view is first show in portrait mode and the rotates to appear on landscape mode. What should I do to make it rotate like in background before appearing.
Thanks for your help.
Found out what the problem was. This thread solved my problem
RootViewController animation transition, initial orientation is wrong
I have an issue issue with the UINavigationController on the iPad. When the app is started in landscape orientation, popping the top view controller from the navigation controller causes the device orientation to turn into portrait and the view displayed slides down when the view that becomes visible and adjusts to portrait orientation. It makes no difference if I initiate the call or if it's done automatically by the back button.
When the app is started in portrait mode and device is turned into landscape later I don't see the same behavior and everything works fine.
Any pointers to where and what to look for to find the cause or workaround suggestions to prevent this from happening are welcome.
Thank you,
Oz
One of the view controllers in your UINavigationController's view hierarchy is not overriding the shouldAutorotateToInterfaceOrientation: method, which by default only returns YES for UIInterfaceOrientationPortrait – so, when that particular view controller comes to the front, it auto-rotates to an orientation it supports.
You can fix this by finding the offending view controller and adding the code below:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Overriden to allow any orientation.
return YES;
}