I have iPhone application that supports only Portrait orientation. I want to add to my project view controller that will support only Landscape orientation? Is it possible? If yes how could I achieve that?
I have tried to crate category file like this:
@implementation UINavigationController (Rotation_IOS7)
-(BOOL)shouldAutorotate
{
return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
If I do this I get this error:
Terminating app due to uncaught exception UIApplicationInvalidInterfaceOrientation
, reason: Supported orientations has no common orientation with the application, and shouldAutorotate is returning YES
I have search through numerous topics and finally found a working solution.
In my example, I have two VC's:
A -> VC that is embedded inside Nav. Controller and should only support Portrait view.
B -> VC that is not embedded inside a VC and should support Landscape only.
I would like to go from view A to view B (by pressing a button) and back to view then A with the specific orientations still correct.
I. Create a Category for UINavigationController and write the following in its .m file: (the code will be automatically called)
II. Create a modal segue between A and B and after that between another one between B and A.
III. Write down in each of the View Controllers .m files the following:
OR
After adding this code. You will be able to change orientation for the single view B.
Edit:
create a category in .h and then implement those methods
use these methods in the view controller where you want to support landscape
I've tried this and it works: http://www.sebastianborggrewe.de/only-make-one-single-view-controller-rotate/
First, add these code to your AppDelegat class.
Then, in your landscape view controller, add this method