簡體   English   中英

UiNavigationController自動旋轉在設備上不起作用?

[英]UiNavigationController Autorotation not Working on Device?

為什么UINavigationController AutoRotation無法在設備上運行? 如何為UinavigationController設置自動旋轉屬性?

    **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] orientation]返回UIDeviceOrientation,而不是UIInterfaceOrientation。

如果要獲取當前的界面方向,可以使用以下方法:

UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];

要么

UIInterfaceOrientation orientation = self.interfaceOrientation; // into UIViewController

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM