2012-06-26 61 views
0

我們僅在肖像模式下顯示某些視圖,僅在橫向模式下顯示某些視圖。我們需要使用側面導航中出現的選項按鈕在這些視圖之間來回切換。通過按下按鈕,導航將打開,側面導航應該適用於縱向和橫向模式。iOS定位問題

默認情況下,登陸屏幕處於縱向模式,從那裏用戶可以切換到橫向視圖,反之亦然。

對於出現在橫向模式下的視圖,無論用戶在此時是否以縱向方向握住設備,它們都必須正常顯示在橫向模式中。當顯示橫向視圖時,用戶外殼將旋轉設備移至橫向播放,反之亦然用於橫向到縱向移動。

什麼將是一個合適的解決方案

回答

0

您的視圖控制器來重寫此方法 - - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

在你只想肖像,使用視圖控制器 -

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 

    return (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown); 
} 

,並在視圖控制器,你想要風景模式,使用 -

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 

    return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||  interfaceOrientation == UIInterfaceOrientationLandscapeRight); 
} 
+0

感謝Rishi,但我想在按鈕上切換設備方向(不是通過使用設備旋轉) – Mudaser

+0

然後,您需要在按鈕單擊時以編程方式處理所有框架,這種按鈕單擊時可完全重新排列視圖。 – rishi

+0

有沒有其他解決方案? – Mudaser