2010-04-15 33 views

回答

47

Code found here

下水

應用在iPhone OS中通常 推出肖像模式以匹配主屏幕的 方向。如果您 有兩個 縱向和橫向模式運行的應用程序,你的應用程序 應始終 肖像模式開始啓動,然後讓 其視圖控制器旋轉 接口需要基礎上, 設備的方向。但是,如果您的 應用程序僅在橫向模式 中運行,則必須執行 以下步驟,以使其最初以橫向 橫向啓動。

  • 在應用程序的Info.plist文件中添加UIInterfaceOrientation
    項並將其值設置爲
    風景模式。對於景觀
    方向,您可以將該值設置這個關鍵的

    UIInterfaceOrientationLandscapeLeft

    UIInterfaceOrientationLandscapeRight.

  • 鋪陳在橫向模式下您的意見,並確保他們的 自動尺寸選項設置正確 。

  • 覆蓋您的視圖控制器的shouldAutorotateToInterfaceOrientation: 方法和返回是隻爲
    所需的橫向和NO
    人像方向。

+0

謝謝。這真的很有幫助。 – Tirth 2010-10-15 06:52:39

+0

總是忘記shouldAutorotateToInterfaceOrientation步驟,沒有你的整個UI出現橫向... – 2011-09-01 08:48:52

10

編輯的plist僅支持風景,然後確保在每一個的UIViewController/uitabbar等,在shouldAutoRotateToInterfaceOrientation,則returnreturn ((interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || (interfaceOrientation == UIInterfaceOrientationLandscapeRight));

+3

甚至更​​好: if(UIInterfaceOrientationIsLandscape(interfaceOrientation)){return YES; }返回NO; – Sangraal 2010-12-22 20:15:24

+5

甚至更​​短:return(UIInterfaceOrientationIsLandscape(interfaceOrientation)) – 2011-07-21 13:32:29

+0

沒有圓括號的情況下更短:-) – 2012-02-16 20:53:47

26

你也只是這一切縮短

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    // Return YES for supported orientations 
    return UIInterfaceOrientationIsLandscape(interfaceOrientation); 
} 
+0

對於簡短和甜蜜的解決方案。 – 2012-02-28 05:24:08

29

爲了讓您的應用程序風景模式只有,你應該使用「支持的界面取向」。 (Targets -> YourApp -> Supported Interface Orientations -> Landscape Left & Right

Supported Interface Orientations

您還應該通過附加的價值觀Landscape (left home button)Landscape (right home button)Supported interface orientations鍵設置的應用程序在應用程序的Info.plist文件(Info.plist file)的方向。 row's

您可以使用willRotateToInterfaceOrientation和/或didRotateFromInterfaceOrientation來處理方向更改。


shouldAutorotateToInterfaceOrientationiOS 6的進出棄用。

返回UIDeviceOrientationLandscapeLeft/RightshouldAutorotateToInterfaceOrientation應該讓你的應用程序的 「風景」:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
    return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight); 
} 

而且還可能會改變你的應用程序的Info.plistView Orientation(如上所述)。


此外,我建議在更改視圖的定向Landscape屬性督察landscape

+1

當時沒有存在,但很高興知道更新的選項 – 2012-07-19 20:28:10