0

我正在使用 xcode4.5.1 中的 Master-detail 模板来创建一个通用应用程序。为了在 iPad 中保持横向,我有以下设置。它适用于 iOS6,但在 iOS5 中始终保持纵向。我该如何解决这个问题?(项目链接:https ://www.dropbox.com/s/7wm9l8kxhan6kp1/itstest.zip )</p>

  1. 列表

    <key>UISupportedInterfaceOrientations~ipad</key>
    
    <array>
    <string>UIInterfaceOrientationLandscapeLeft</string>
    <string>UIInterfaceOrientationLandscapeRight</string>
    
    </array>
    
    <key>UISupportedInterfaceOrientations~iphone</key>
    
    <array>
    <string>UIInterfaceOrientationPortrait</string>
    <string>UIInterfaceOrientationPortraitUpsideDown</string>
    
    </array>
    
  2. 甚至在 Appdelegate.m 中添加以下内容

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
        return UIInterfaceOrientationIsLandscape(interfaceOrientation);
    }
    

谢谢!

4

1 回答 1

1

The method shouldAutorotateToInterfaceOrientation does not get called in your AppDelegate, only in your View Controllers (docs). Place the following code inside your view controllers (Although for your particular project I think it would be enough to place it only inside your MasterViewController):

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
        return UIInterfaceOrientationIsPortrait(interfaceOrientation);
    else
        return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
于 2012-12-31T02:43:15.680 回答