Answer the question
In order to leave comments, you need to log in
Screen orientation problem?
There are two controllers FirstViewController and SecondViewController they are in NavigationController.
It is necessary that the FirstViewController be only in portrait orientation, and the SecondViewController in all.
Tried like this:
In NavigationController added
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft;
}
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
Answer the question
In order to leave comments, you need to log in
As timokhin said, orientation information is taken from the root controller, if your root is navigationController, then we create a class and inherit it from UINavigationController.
We add three methods that take the value from the top controller:
//
// NavigationController.h
//
#import <UIKit/UIKit.h>
@interface NavigationController : UINavigationController
@end
//
// NavigationController.m
//
#import "NavigationController.h"
@implementation NavigationController
-(BOOL)shouldAutorotate
{
return [self.topViewController shouldAutorotate];
}
-(NSUInteger)supportedInterfaceOrientations
{
return [self.topViewController supportedInterfaceOrientations];
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return [self.topViewController preferredInterfaceOrientationForPresentation];
}
@end
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
- (BOOL)shouldAutorotate
{
UIViewController *viewController = [(UINavigationController *)self.selectedViewController topViewController];
return [viewController shouldAutorotate];
}
- (NSUInteger)supportedInterfaceOrientations
{
UIViewController *viewController = [(UINavigationController *)self.selectedViewController topViewController];
return [viewController supportedInterfaceOrientations];
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
UIViewController *viewController = [(UINavigationController *)self.selectedViewController topViewController];
return [viewController preferredInterfaceOrientationForPresentation];
}
I haven't tried it myself, but judging by the documentation, these methods will only work if:
-(BOOL)shouldAutorotate{
return YES;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question