在通用的Xcode 6项目中仅停止iPhone屏幕旋转

20
随着Xcode 6的推出,苹果公司移除了在通用应用程序中轻松拥有多个iPad和iPhone故事板的功能。由于这个原因,在旋转面板/设置中您无法区分iPad和iPhone。
我该如何阻止iPhone应用程序进入横向模式,同时仍允许iPad应用程序进行此操作?
这只能通过编程完成吗?如果是这样,那我仍在使用Objective C,而不是Swift。
3个回答

55

删除所有其他答案的代码。进入您的 Info.plist 文件并添加以下内容。

  • "Supported Interface Orientations" - 数组
    • "Portrait (bottom home button)" - 字符串
    • "Portrait (top home button)" - 字符串
  • "Supported Interface Orientations (iPad)" - 数组
    • "Portrait (bottom home button)" - 字符串
    • "Portrait (top home button)" - 字符串
    • "Landscape (left home button)" - 字符串
    • "Landscape (right home button)" - 字符串

1
原始键 - UISupportedInterfaceOrientations〜ipad - Underdog

2

请查看这个答案。

基本上,您需要在UINavigationControllerUITabBarController子类上实现Chris1994的答案,然后将以下内容添加到该Nav或Tab控制器上的第一个UIVIewController 子类中:

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}

0
    - (NSUInteger) supportedInterfaceOrientations
    {
        NSString *device = [UIDevice currentDevice].model;

        if([device isEqualToString:@"iPhone"])
        {
            return UIInterfaceOrientationMaskPortrait;
        }
        else
        {
        return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscape;
        }
    }

- (BOOL)shouldAutorotate
{
if([device isEqualToString:@"iPhone"])
  {
     return NO;
  }
  else
  {
      return YES;
  }
}

构建失败,原因是未知的接收器 - 'device'。我已将其放置在ViewController.m文件中。这样正确吗? - InfinityLoop
@WillWoodruff,是的,但抱歉,在bool should rotate中复制NSString *device = [UIDevice currentDevice].model;有一个错误。 - Chris1994
虽然提供的代码不再产生任何错误,但它仍无法停止旋转。有什么想法吗? - InfinityLoop

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接