2014-02-24 31 views
2

我在我的應用程序中有兩個視圖; 「計算器」和「磁帶」。我可以點擊計算器裏面的按鈕來找到磁帶,反之亦然。我按照下面的代碼設置了輪轉,大部分時間都能正常工作。自動旋轉ios6不按預期工作

但是,如果我將計算器視圖或磁帶視圖旋轉到橫向,然後如果我嘗試訪問其他視圖,界面就會全部混亂,就像它無法識別該設備已被旋轉一樣。有什麼建議麼?

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation) toInterfaceOrientation duration:(NSTimeInterval)duration 
{ 
    [self doLayoutForOrientation:toInterfaceOrientation]; 
} 


- (void)doLayoutForOrientation:(UIInterfaceOrientation)orientation { 
if (UIInterfaceOrientationIsPortrait(orientation)) 
{ 
//set the frames here 
} 
else 
{ 
//set the frames here 
} 
} 
+0

當您從已經旋轉的視圖轉到另一個視圖(比如磁帶)時,設備無法識別該視圖已被更改。 –

+0

所以你需要檢查設備的當前方向,在視圖中會出現下一個視圖並調整視圖 –

+0

好極了,像夢一樣工作。 –

回答

2

這些代碼寫在視圖中會出現每個視圖。

UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation]; 
if(orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight) 
{ 
//adjust the view for landscape 
} 
else if(orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) 
{ 
//adjust the view for portrait. 
}