Ios UiNavigationController自动旋转在设备上不工作?
为什么UINavigationController自动旋转在设备上不工作?如何为UinavigationController设置自动旋转属性Ios UiNavigationController自动旋转在设备上不工作?,ios,xcode,uinavigationcontroller,nsnotifications,autorotate,Ios,Xcode,Uinavigationcontroller,Nsnotifications,Autorotate,为什么UINavigationController自动旋转在设备上不工作?如何为UinavigationController设置自动旋转属性 **BusinessCardAppDelegate.m** - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [self.window
**BusinessCardAppDelegate.m**
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[self.window makeKeyAndVisible];
RootView *rView=[[RootView alloc]initWithNibName:@"RootView" bundle:nil];
self.naviGationController =[[[UINavigationController alloc]initWithRootViewController:rView]autorelease];
[self.window addSubview:naviGationController.view];
return YES;
}
**RootView.m**
- (void)viewDidLoad
{
[super viewDidLoad];
self.title =@"BusinessCard";
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationFunction:) name:UIDeviceOrientationDidChangeNotification object:nil];
}
-(void)orientationFunction:(NSNotification*)notification
{
UIInterfaceOrientation orientation = [[UIDevice currentDevice] orientation];
switch (orientation)
{
case UIDeviceOrientationPortrait:
/* AlertView Show*/
break;
case UIDeviceOrientationPortraitUpsideDown:
/* AlertView Show*/
break;
case UIDeviceOrientationLandscapeLeft:
/* AlertView Show*/
break;
case UIDeviceOrientationLandscapeRight:
/* AlertView Show*/
break;
default:
break;
}
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
为什么这不能在设备上运行,但在模拟器中运行良好?我不明白为什么这不起作用?
提前感谢。
[[UIDevice currentDevice]方向]
返回UIDeviceOrientation,而不是UIInterfaceOrientation
如果要获取当前界面方向,可以使用以下命令:
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
或
UIInterfaceOrientation orientation = self.interfaceOrientation; // into UIViewController