0

为什么UINavigationController AutoRotation在设备上不起作用?如何为UinavigationController设置自动旋转属性?UiNavigationController Autorotation无法在设备上工作?

**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 [email protected]"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; 
} 

为什么这不是在设备上工作,但在模拟器中工作正常?我不明白为什么这不起作用? 在此先感谢。

回答

0

[[UIDevice currentDevice] orientation]返回UIDeviceOrientation,而不是UIInterfaceOrientation。

如果你希望得到您的当前界面的方向,你可以使用如下:

UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation]; 

UIInterfaceOrientation orientation = self.interfaceOrientation; // into UIViewController 
相关问题