2012-07-23 167 views
2

我有一個splitcontroller和有模式地顯示來自detailcontroller的viewDidLoad中(它的登錄屏幕)一個模式的普遍應用檢測上的應用程序啓動正確的方向

當打開iPad版,我想能夠在縱向或橫向上啓動它取決於設備的初始方向。問題在於它始終以縱向形式啓動(預計按照documentation)。

如果我有設備作爲肖像,然後轉動景觀,它的作品。但是如果我直接打開應用程序,它不會。

BTW:我已經設置return true在那個登錄的viewController的(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

更新: 如果我從viewDidAppear而不是viewDidLoad中進行SEGUE,模態的方向正常工作,但SplitController被視作一個而在模態之前,我該如何避免這種情況?

- (void)viewDidAppear:(BOOL)animated 
{ 
    [self.splitViewController performSegueWithIdentifier:@"toModal" sender:self.splitViewController]; 
} 

回答

1

您可以有條件地設置(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation的方向。這樣的事情是不漂亮,但它的工作原理:

UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation; 

if(orientation == 0) //Default orientation 
    //UI is in Default (Portrait) -- this is really a just a failsafe. 
else if(orientation == UIInterfaceOrientationPortrait) 
    //Do something if the orientation is in Portrait 
else if(orientation == UIInterfaceOrientationLandscapeLeft) 
    // Do something if Left 
else if(orientation == UIInterfaceOrientationLandscapeRight) 
    //Do something if right 

否則這個職位看起來很相對於你想做什麼:

Launching application in landscape orientation for IPad


提案2


您可以創建一個具有方法的類來查找dev的方向冰(即使用 'deviceInfo'):

UIInterfaceOrientationIsPortrait([[UIApplication sharedApplication]statusBarOrientation]) 

UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication]statusBarOrientation]) 

您還可以存儲任何拉伸因素/尺寸/測量你在乎曾經擁有。然後在view-(id)initWithFrame:(CGRect)frame中,您可以調用您的方法來檢查方向(即deviceInfo.isLandscape?)。然後設定你viewautoresizingMask等於UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth。然後,在-(void)layoutSubviews設置view.frame等於你想要什麼尺寸:

CGRectMake(x-origin, y-origin, width, height); 

以下是獲取當前方向的基準:

http://www.ddeville.me/2011/01/getting-the-interface-orientation-in-ios/

更改視圖框的尺寸相對簡單並可以在蘋果的文檔或一些簡單的谷歌搜索中找到。

+0

不工作。我已經把這些代碼放回原處,並接受所有的方向,但它只能顯示肖像 – dimirc 2012-07-24 00:53:48

相關問題