<分区>
<分区>
Possible Duplicate:
Landscape Mode ONLY for iPhone or iPad
我正在制作一款仅适用于 iPad 的应用程序,我希望整个应用程序都是横向的。
我对 iOS 编程非常很陌生,并且正在使用 StoryBoard 方法来创建界面。
当我第一次设置应用程序时,我选择了一个 View 并单击按钮以使其仅横向显示。我发现这只让它以横向启动,但并不能阻止用户手动旋转。
所以,我发现我必须这样做:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if (interfaceOrientation == UIDeviceOrientationLandscapeLeft || interfaceOrientation == UIDeviceOrientationLandscapeRight)
{
return YES;
}
return NO;
}
为了防止用户手动旋转它。
现在,我创建了一个导航 Controller 和一个设置为 Root View Controller 的常规 View 。我还在该 View 中添加了一个按钮。
我的问题是,我的应用程序似乎仅在第一次启动时是横向的(字面上闪烁横向),但随后仅在导航 Controller 中是纵向的。
我还发现导航 Controller 和 Storyboard 界面中的第一个 View Controller 都选择了“方向:横向”。
即使我将设备旋转至横向,应用程序也不会旋转。尽管所有设置都仅适用于横向,但它似乎陷入了纵向状态。
如何使我的应用程序仅横向显示而不是当前的仅纵向状态?
编辑:我实际上找到了自己的解决方案。
似乎链接到导航 Controller 的 View 未链接到我仅为横向设置代码的类文件。
我所做的就是在 Storyboard 界面中选择 View Controller,单击右侧边栏上的“Show Identity Inspector”按钮,然后将类设置为我的 ViewController 文件的名称,其中代码:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
是。
简而言之,我的 View Controller 未链接到 View Controller 类文件。
最佳答案
不建议返回 YES
和 NO
。
返回 UIDeviceOrientationLandscapeLeft
但是应该使您的应用程序“仅限横向”:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
如果这不起作用,请导航到您的 Info.plist
并添加一个支持的界面方向
行,其中包含横向(左主页按钮)
和横向(右主页按钮)
。
此外,我建议将 View 方向更改为横向
属性检查器。
关于iphone - 导航 Controller (及其所有 View )仅是纵向的。我怎样才能把它们变成风景呢?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11548516/