代码之家  ›  专栏  ›  技术社区  ›  nacho4d

如何将我的应用程序限制为横向模式?

  •  13
  • nacho4d  · 技术社区  · 14 年前

    我想知道什么是将我的应用程序限制为横向模式的最佳方法?

    shouldAutorotateToInterfaceOrientation: DetailViewController.m中的方法

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

    但是 4.2通用汽车仍有缺陷

    提前谢谢。

    更新1

    • Bug ID #8620135

    • 我的应用程序快完成了,我必须找到一个自大的工作,因为我认为他们不会在4.2正式发布之前解决这个问题(通用已经发布了!)

      为了重新创建bug,只需在任何UIViewControllers(rootviewcontrollers或DetailViewControllers)中使用SplitView模板并重写上面的方法

    更新2

    我找到了一份工作。(有关完整的解决方案,请参见更新3)

    将UISupportedInterfaceOrientations设置为仅支持横向,这将强制应用以横向模式启动,从而允许DetailViewController正确启动(因此正确显示)

    <key>UISupportedInterfaceOrientations</key>
    <array>
        <string>UIInterfaceOrientationLandscapeLeft</string>
        <string>UIInterfaceOrientationLandscapeRight</string>
    </array>
    

    但如果你旋转设备,它会变成肖像模式!!!,所以 shouldAutorotateToIntercafeOrientation :如上所述

    讨论:

    如果这不是一个bug,那么当以视图控制器不支持的方向启动应用程序时,我会期望出现警告或执行错误、异常或其他情况。另外,为什么只有DetailViewController不显示?如果这是规范,那么RootViewController也应该无法加载。你不觉得吗?

    更新3

    真正的问题似乎是,在iOS4.2gmuisplitviewcontroller中,它需要所有的控制器在加载时都有所有的旋转。所以有必要欺骗他,使其加载在横向模式,然后不允许他旋转其视图控制器。

    所以这里是这个烦人的iBug的新工作。

    步骤1: 设置Info.plist如下:

    <<阵列>
    <string>UIInterfaceOrientationLandscapeLeft</字符串>
    </阵列>
    

    在DetailViewController.m或.h(来自SplitView模板)中设置新标志

    BOOL lockRotation = NO; //WORK-ARROUND: Bug ID# 8620135.
    
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
        //WORK-ARROUND: Bug ID# 8620135.
        if (lockRotation) {
            return UIInterfaceOrientationIsLandscape(interfaceOrientation);
        }else{
            return YES;
        }
    }
    - (void)viewDidLoad {
        [super viewDidLoad];
        //set NO here since this is called before shouldAutorotateToInterfaceOrientation method is called
        lockRotation = NO; //WORK-ARROUND: Bug ID# 8620135.
    }
    - (void)viewDidAppear:(BOOL)animated {
        //set YES as soon as possible, but after shouldAutorotateToInterfaceOrientation method was called
        lockRotation = YES; //WORK-ARROUND: Bug ID# 8620135.
        [super viewDidAppear:animated];
    }
    

    重要提示: 请注意,此错误仅在加载UISplitViewController时出现,而不是每次都出现 its视图出现。因此,要查看此错误,请确保之前已终止应用程序。

    4 回复  |  直到 13 年前
        1
  •  2
  •   Community paulsm4    7 年前

    我悬赏500英镑问了一个问题 seems to be the same thing you're facing .

    从我有限的经验来看,制作一款纯风景的iPhone应用程序要比制作纯风景的iPad应用程序容易得多。我不知道为什么会有什么不同,但苹果公司说要采取的步骤,使它的景观只对他们自己不起作用。

        2
  •  1
  •   Bushra Shahid    13 年前

    试试这个(它有效):

    -(BOOL)shouldAutorotateToInterfaceOrientation(UIInterfaceOrientation)toInterfaceOrientation {
        if(toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)
            return YES;
        }
        else 
        {
            return NO;
        }
    }
    
        3
  •  0
  •   Community paulsm4    7 年前

    iPhone app in landscape mode ,如果你还没有。我只是建议在Info.plist中添加ui支持界面方向,并指定两个横向方向。但是,显然,根据被引用问题的答案,这还不够。

        4
  •  0
  •   JapCon    14 年前

    我相信这是一个错误,我也面临这个问题。这和

    UIInterfaceOrientationLandscapeLeft
    

    要复制这种情况:

    1) 使用UISplitViewController模板创建新的iPad项目

    2) 编辑信息列表

    Supported interface orientations
    -Landscape (left home button)
    -Landscape (right home button)
    

    3) 详细视图控制器.m

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    //    return YES;
     NSLog(@"RotateToInterface:[%d] vs LandscapeLeft[%d]", interfaceOrientation, UIInterfaceOrientationLandscapeLeft);
     return interfaceOrientation == UIInterfaceOrientationLandscapeLeft;
    }
    

    4) 运行它…你会看到一个空白的黑色视图。不管你怎么转身。”从未检测到“UIInterfaceOrientationLandscapeLeft”。

    nacho4d 添加BOOL check的工作正在进行中。竖起大拇指:)