在IOS6中无法setStatusBarOrientaion

时间:2012-10-09 10:08:01

标签: ios6

使用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;
}
....

MainViewController.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];
}
...

1 个答案:

答案 0 :(得分:0)

从iOS 6.0 SDK发行说明:

  

setStatusBarOrientation:animated:方法不会被彻底弃用。现在,只有当最顶层的全屏视图控制器的supportedInterfaceOrientations方法返回0时,它才有效。这使得调用者负责确保状态栏方向一致。