2010-08-05 36 views
0

我創建了一個modalviewcontroller,所有的子視圖都是由代碼創建的。當我測試應用程序時,我發現一個問題。那麼問題的主要原因是應用程序不應該支持UpsideDown方向,但設備可能恰好處於該方向。如何從iPhone(而不是DeviceOrientation)獲取InterfaceOrientation?

如果我:

  1. 設備旋轉爲縱向,然後倒置的模式和presentModalView,在modalviewcontroller子視圖應該出現相同的縱向方向。

  2. 將設備旋轉到橫向,然後到UpsideDown模式和presentModalView,子視圖應該被區別對待。

上面的情況告訴我,我應該根據以前的InterfaceOrientation在modalviewcontroller中創建子視圖。

問題是:如何獲得前一個屏幕的InterfaceOrientation?在這種情況下獲取設備定位不會有任何幫助。我正在寫一個庫,我可能會給我的用戶界面發送給我「toInterfaceOrientation-willRotateToInterfaceOrientation:duration:,但是有沒有關於如何在我的代碼中獲取方向的任何想法?

回答

9

在任何UIViewController中,你可以訪問屬性interfaceOrientation這樣的:

if (self.interfaceOrientation == UIInterfaceOrientationPortrait) { 
    // do stuff 
} 
+0

**注:**'interfaceOrientation'在IOS版本8.0中已停用 – 2015-06-26 05:57:52

0
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    return UIInterfaceOrientationIsPortrait(interfaceOrientation); 
} 
相關問題