iphone - 导航 Controller (及其所有 View )仅是纵向的。我怎样才能把它们变成风景呢?

标签 iphone ios cocoa-touch ipad storyboard

<分区>

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 类文件。

最佳答案

不建议返回 YESNO

返回 UIDeviceOrientationLandscapeLeft 但是应该使您的应用程序“仅限横向”:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

如果这不起作用,请导航到您的 Info.plist Info.plist file

并添加一个支持的界面方向行,其中包含横向(左主页按钮)横向(右主页按钮)

row's

此外,我建议将 View 方向更改为横向 属性检查器

landscape

关于iphone - 导航 Controller (及其所有 View )仅是纵向的。我怎样才能把它们变成风景呢?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11548516/

上一篇:iphone - 游戏中心 IBAction 成就

下一篇:ios - InAppSettingKit subview 的 setHiddenKeys

相关文章:

iphone - cocos2d版本升级后 Sprite 闪烁伪影

ios - 当一个应用程序从后台启动时,applicationDidBecomeActive 会被调用吗?

iOS:容器 View Controller 模式

iphone - 在字符串中存储单词的优雅算法

ios - 我如何确定 NSData 的内容何时指示 Web 服务请求失败?

iphone - 有没有办法在我的应用程序中不使用 CLLocationManager 委托(delegate)来获取当前位置

ios - 将较小的音频文件从iOS应用上传到Python-Flask服务器

iOS SpriteKit 节点位置

iphone - 使用 iPhone API 拍照并将其传输到服务器

iphone - 触摸内部拖动会反复触发声音,并且内部触摸不起作用