Reputation: 1048
Application is portrait locked but there is this only video screen when I need to allow landscape orientation as well. My implementation is as follows:
in project file
Created custom navigation controller and overridden following methods :
- (NSUInteger)supportedInterfaceOrientations
{
NSUInteger supportedOrientation = [[self.viewControllers lastObject] supportedInterfaceOrientations];
return supportedOrientation;
}
Now lets say in application I have 4 view controllers as follows :
So in each view controller overridden
- (NSUInteger)supportedInterfaceOrientations
{
}
and returned UIInterfaceOrientationMaskPortrait
or UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight
depending on the view controller support.
I am using storyboard
and Xcode 5.0.2
Our custom Navigation controller is root view controller. Home is on top of it, and in view will appear depending on count of some maintained list we either stay or navigate to List View controller using push segue.
From Video and setting view controller we have unwind segue which is connected to Home View controller.
If I go from portrait(Video) to setting, it remains portrait locked as expected.
Problems :
Some has suggested to implement shoudAutorotate
as well. Have tried to return NO from portrait screens and YES from video View Controller (Trivially shouldAutorotate
is implemented for custom navigation controller like supportedInterfaceOrientations
implementation). But with this if steps from Problem 1 are followed, setting screen gets locked to landscape.
If there is any other suggestion? or is something missing?
Upvotes: 0
Views: 1168
Reputation: 62072
If I understand the problem correctly, this is the method you're looking for:
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return UIInterfaceOrientationPortrait;
}
If you give your view controllers a preferred interface orientation, they will try to start at that orientation and then rotate to the appropriate orientation based on the supported interface orientations and whether or not auto-rotate is allowed for the view controller in question.
Upvotes: 1
Reputation: 6823
Issue 1, I believe is expected behaviour: Source: Force Rotate UIViewController
Bottom line, if you have a view that only accepts landscape, you can use the following to force iOS to change the orientation. It's curious, but it works. I apologize that I can't give credit to the original author, but once came across this elsewhere on StackOverflow:
Issue 2, I believe you can use the relevant UINavigationController
methods instead:
navigationController:willShowViewController:animated:
Upvotes: 0