Rotation on certain screens
How do I set only one UIViewController
to be enabled in rotation?
The scenario is as follows:
I own 5 screens, and in all of them I must enable only the mode portrait. But I have a sixth screen, and this should be enabled the modes in landscape.
Note: Currently my project settings are to accept only portrait
mode.
3 answers
Do the following:
Create a project in Xcode 6.1.1
with template Tabbed Application
because it is faster to develop and demonstrate the functionality. I did in Swift but it should be equal in Objective-C
You will have Tab Bar Controller
and two related views being:
FirstViewController
and a SecondViewController
In one of the views (FirstViewController
for example) do as in the figure below. The other leave everything in Default (Orientation: inferred, etc.). For min only the fixed portrait orientation in view FirstView
Worked when I unchecked the option Resize view from NIB
.
That's it ! Works: only FirstView
gets fixed orientation. The SecondView
allows the change of orientation to suit the new dimensions.
You can download the project at https://github.com/joao-parana/only-one-can-landscape .
- Enable in the project settings all the guidelines you will need. (In your case it enables everything, as I understand it.)
-
In all
UIViewController
's of your project implement thesupportedInterfaceOrientations
method by returning the desired configuration.Example in controller that will support all returns
UIInterfaceOrientationMaskAll
in the others returnsUIInterfaceOrientationMaskPortrait
- if you are using Storyboard leave everything marked as
inferred
inSimulated Metrics
Hello, no AppDelegate.H add
@property (nonatomic , assign) bool blockRotation;
And no AppDelegate.m
-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
if (self.blockRotation) {
return UIInterfaceOrientationMaskPortrait;
}
return UIInterfaceOrientationMaskAll;
}
And in the views you want to disable rotation, just add
- (void)viewDidLoad
{
[super viewDidLoad];
AppDelegate* shared=[UIApplication sharedApplication].delegate;
shared.allowRotation=YES;
}
-(void)viewWillDisappear:(BOOL)animated{
AppDelegate* shared=[UIApplication sharedApplication].delegate;
shared.allowRotation=NO;
}
Another way is to add in each view the check
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if(interfaceOrientation == UIInterfaceOrientationPortrait)
return YES;
return NO;
}
Source: https://stackoverflow.com/questions/5296399/ios-how-to-stop-view-rotate