我试图让我的应用程序在设备本身旋转时旋转界面,但我无法做到正确 . 我在plist info文件中添加了支持的接口,并为shouldRotateToInterfaceOrientation返回yes .
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
return YES;
} else {
return NO;
}
}
这是如何实现轮换的?
请帮忙!
4 回答
也许尝试编辑info.plist并在那里添加您支持的方向?
选择项目 - >选择目标 - >信息 - >支持的界面方向,然后单击加号4次以支持这些方向:
希望能帮助到你!
确保已将
shouldRotateToInterfaceOrientation
添加到要支持不同方向的视图控制器 . 它不会进入app委托 .如果您使用标准UI元素,支持方向是直截了当的,因此,假设情况如此,您就是在正确的轨道上 .
如果您正在使用UITabController,则所有视图必须支持相同的方向,否则默认为最小(例如Portrait),我相信 .
此外,如果您正在为视图使用NIB,请确保在Interface Builder中配置视图时选中了“自动调整子视图” .
如果你使用
UITabBarController
,那么你'll need to call it'的子视图'shouldAutoratateToInterfaceOrientation
.假设您有两个选项卡,请尝试将以下两行添加到使用
UITabViewController
的类中的方法shouldAutorotateToInterfaceOrientation
.当然"tabBarController"必须通过IB链接到XIB文件中的
UITabBarController
.谢谢,