4

我试图让我的应用程序在设备本身旋转时旋转界面,但我做不到。我在 plist 信息文件中添加了支持的接口,并为 shouldRotateToInterfaceOrientation 返回了 yes。

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {  
    if (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight) {  
        返回是;  
    } 别的 {  
        返回否;  
    }  
}

这是如何实现轮换的?
请帮忙!

4

4 回答 4

1

也许尝试编辑 info.plist 并在那里添加您支持的方向?

选择您的项目 --> 选择您的目标 --> 信息 --> 支持的界面方向并单击加号 4 次以支持这些方向:

Item 0   Landscape (left home button)
Item 1   Landscape (right home button)
Item 2   Portrait (top home button)
Item 3   Portrait (bottom home button)

希望能帮助到你!

于 2012-06-19T12:55:48.680 回答
0

如果您正在使用UITabBarController,那么您需要将其称为 subviews' shouldAutoratateToInterfaceOrientation

假设您有两个选项卡,请尝试将以下两行添加到shouldAutorotateToInterfaceOrientation使用UITabViewController.

[[tabBarController.viewControllers objectAtIndex:0] shouldAutorotateToInterfaceOrientation:interfaceOrientation];
[[tabBarController.viewControllers objectAtIndex:1] shouldAutorotateToInterfaceOrientation:interfaceOrientation];

当然,“tabBarController”必须UITabBarController通过 IB 链接到您的 XIB 文件中。

谢谢,

于 2011-05-30T04:17:52.443 回答
0

如果您使用标准 UI 元素,那么支持方向是直截了当的,因此,假设是这种情况,您就走在了正确的轨道上。

如果您使用的是 UITabController,我相信所有视图都必须支持相同的方向,否则默认为最小值(例如肖像)。

此外,如果您在视图中使用 NIB,请确保在 Interface Builder 中配置视图时选中“自动调整子视图”。

于 2011-01-04T23:57:07.347 回答
0

确保您已将shouldRotateToInterfaceOrientation要支持不同方向的视图控制器添加到视图控制器中。它不会进入应用程序委托。

于 2011-01-04T23:43:52.273 回答