0

当我使用 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];
}
...
4

1 回答 1

0

从 iOS 6.0 SDK 发行说明:

setStatusBarOrientation:animated: 方法并未完全弃用。它现在仅在最顶层全屏视图控制器的 supportedInterfaceOrientations 方法返回 0 时才有效。这使得调用者负责确保状态栏方向一致。

于 2012-10-20T00:39:08.440 回答