【问题标题】:How to make my interface orientation automatically rotate to portrait?如何使我的界面方向自动旋转为纵向?
【发布时间】:2012-09-24 11:04:39
【问题描述】:

我正在尝试让我的一个 xib 文件旋转为纵向,就好像它首先是默认设置一样。

我让我的应用只支持横向。在 plist 中,我将“初始界面方向设置为横向(右主页按钮)”,因为大多数应用程序在横向模式下运行。

我在实现文件中的代码是:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations

return interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight;

}

现在,当更改为需要界面处于纵向模式的视图控制器时,我已将此代码放在 xib 文件的实现文件中,以使其进入纵向模式并单独支持纵向模式。这样即使设备处于横向模式,它仍然会以纵向模式运行视图。

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations

return interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortrait;

}

虽然这似乎不起作用。它只是保持在横向模式并挤压图像视图和我放在 xib 文件中的其他对象。如何让 xib 旋转到纵向模式?谢谢。

【问题讨论】:

  • iOS 6 新增了 3 种方便界面旋转的方法,查看:stackoverflow.com/questions/12404556/…
  • 哪个iOS版本以及如何更改viewController?
  • 您使用哪种方法来获取视图.. pushviewcontroller 或 presentModalViewController
  • @jcesar 我实际上是从 iOS5 开始我的项目

标签: iphone ios xcode cocoa


【解决方案1】:
  change your Xib in Landscape Mode only and then click on your project file then target   then select only Landscape mode or Portrait Mode(left/right or both) 
  then go to this method 
I am using Landscape Mode.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
  // Return YES for supported orientations
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}

【讨论】:

    【解决方案2】:

    我的经验表明,在 plist 文件中设置 UIInterfaceOrientation 没有任何效果。另一方面,您可以通过设置在启动时强制一个方向(例如横向):

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft];
        // your stuff
    {
    

    您以后也可以使用此方法来强制设备的逻辑方向。注意:这是 Apple 的“官方”方法,截至this document

    【讨论】:

      猜你喜欢
      • 2012-12-13
      • 1970-01-01
      • 2018-03-16
      • 1970-01-01
      • 2015-10-25
      • 1970-01-01
      • 1970-01-01
      • 2018-01-11
      • 1970-01-01
      相关资源
      最近更新 更多