6

我正在使用splitviewcontroller作爲我的應用程序的rootview。我需要將登錄和註冊視圖顯示爲splitviewcontroller頂部的模式視圖。當我嘗試從splitViewController的rootview的viewdidAppear方法呈現登錄/ reg視圖時,它不顯示。我嘗試使用以下代碼從Appdelegate的didFinishLaunching方法中提供登錄/註冊視圖UISplitViewController和方向 - iOS <5.0

[self.window.rootViewController presentModalViewController:self.navController animated:NO]; 

它工作。

我的問題是,應用程序同時支持橫向方向,但是當我在設備中運行它時,無論在哪個方向上,我都拿着設備,我只獲取LandscapeRight作爲方向。因此,如果我將設備放在LandscapeLeft方向,則應用程序會與登錄屏幕顛倒。我正在使用LandscapeLeft &正確支持info.plist上的方向。

請幫我解決問題。當我們將splitViewcontroller作爲應用程序的rootview時,我們將如何呈現視圖?

在iOS 5.0(僅限)中,我能夠顯示來自splitviewcontroller的rootview控制器 - viewdidAppear方法的登錄視圖。在所有其他操作系統版本中,這種情況不起作用,我需要從Appdelegate的didFinishLaunching方法中提出它。

+0

在登錄屏幕的控制器中,您是否實現了' - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation'以獲得您所需的兩個方向? – 2012-01-07 04:53:22

+0

正確的方法應該來自您的splitViewController的viewDidAppear方法,您可以在iOS 5上使用它。您能否提供源代碼以便我們看到它的外觀?也許在那裏可能會有不同的做法。 – 2012-01-19 23:23:47

回答

0

如果我沒有記錯的話,iOS會誤報實際的方向,直到第一次旋轉

也IIRC,使用[[UIApplication sharedApplication] statusBarOrientation]繞過這個問題。

-1

從窗口中刪除登錄視圖後,根據設備的方向使用以下代碼設置rootviewcontroller的方向。

#define DegreesToRadians(x) ((x) * M_PI/180.0) 

[LoginviewContoller.view removeFromSuperview] 

self.viewController = [[[ExampleViewController alloc] initWithNibName:@"ExampleViewController" bundle:nil] autorelease]; 

switch(self.viewController.interfaceOrientation) 

{ 
case UIInterfaceOrientationPortrait:    
    NSLog(@"potrait");    
    break; 
case UIInterfaceOrientationPortraitUpsideDown: 
    NSLog(@"prtraitdown"); 
    break; 
case UIInterfaceOrientationLandscapeLeft: 
    self.viewController.view.transform = 
    CGAffineTransformMakeRotation(DegreesToRadians(270)); 
    NSLog(@"lanscapelef"); 
    break; 
case UIInterfaceOrientationLandscapeRight: 
    self.viewController.view.transform = CGAffineTransformMakeRotation(DegreesToRadians(90)); 
    NSLog(@"landcsape righ"); 
    break; 
} 

[self.window addSubview:self.viewController.view]; 

它會根據設備方向加載Rootview控制器。