2011-11-24 109 views
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 
相關問題