【问题标题】:How to force UIInterfaceOrientation?如何强制 UIInterfaceOrientation?
【发布时间】:2012-02-02 04:46:36
【问题描述】:

我正在编写一个应用程序并遇到两个问题。我整晚都在网上搜索但没有成功,想知道这里是否有人可以提供帮助。

  1. 当应用程序启动时,我希望它默认为横向模式并检测它是在 UIInterfaceOrientationLandscapeLeft 还是 UIInterfaceOrientationLandscapeRight。我在 .xib 文件中以横向模式创建了 UI。但是,当我检查 self.interfaceOrientation 时,它总是返回 UIInterfaceOrientationLandscapeLeft,而不管 iPad 模拟器中的主页按钮是在左侧还是右侧。

  2. 当用户在两个横向之间旋转 iPad 时,我希望视图发生变化。用一个简化的例子来说明,如果是UIInterfaceOrientationLandscapeLeft,我想在屏幕左侧写1,在屏幕右侧写2。在 UIInterfaceOrientationLandscapeRight 中,在屏幕左侧写入 2,在屏幕右侧写入 1。每当用户旋转设备时,iOS 中的哪种方法可以告诉我?

非常感谢。

【问题讨论】:

    标签: ios uiinterfaceorientation


    【解决方案1】:
    1. 你在哪里检查?如果您在applicationDidFinishLaunching 或视图控制器的viewDidLoad 中执行此操作,则可能界面方向尚未正确设置。等到viewWillAppearviewDidAppear 进行检查。

    2. 在您的视图控制器中查看shouldAutorotateToInterfaceOrientation。您需要将YES 返回到支持的方向,因此在您的情况下,如果interfaceOrientation 是横向,则您希望返回YES(顺便说一句,有一个用于检查横向与纵向的辅助函数)。另请查看didRotateFromInterfaceOrientation,它会告诉您用户何时旋转。

    【讨论】:

    • 1.我通过添加 NSLog 语句在 shouldAutorotateToInterfaceOrientation 中检查了它。这可能不是最好的方法,因为在我添加 NSLog 后,它似乎永远不会从 shouldAutorotateToInterfaceOrientation 返回“是”。 2. 谢谢,我会检查您提供的链接。
    猜你喜欢
    • 2011-02-10
    • 1970-01-01
    • 1970-01-01
    • 2019-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-22
    相关资源
    最近更新 更多