当我使用 UINavigationController 时,方向状态不会改变。这是我的代码:
AppDelegate.h 文件
#import <UIKit/UIKit.h>
@class MainViewController;
@interface AppDelegate : UIResponder<UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) MainViewController *mainViewController;
@end
AppDelegate.m 文件
...
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDistionary* launchOptions
{
self.window = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen]bounds]];
self.mainViewController = [[MainViewController alloc]initWithNibName:@"MainViewController" bundle:nil];
UINavigateionController *navigationController = [[UINavigationController alloc]initWithRootViewController:self.mainViewController];
self.window.rootViewController = navigationController;
[self.window makeKeyAndVisible];
return YES;
}
....
主视图控制器.m
...
-(NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskLandscapeLeft;
}
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
return UIInterfaceOrientationMaskLandscapeLeft;
}
-(BOOL)shouldAutorotate{
return YES;
}
-(void) viewDidAppear:(BOOL)animated {
[UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationLandscapeLeft;
[self.navigationController setNavigationBarHidden:YES];
}
...