首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >无法强制应用程序仅在iOS9中使用肖像

无法强制应用程序仅在iOS9中使用肖像
EN

Stack Overflow用户
提问于 2016-01-02 13:06:30
回答 3查看 2K关注 0票数 3

我需要我的应用程序只支持肖像方向。但是在升级到iOS9之后,定向设置似乎没有任何效果。我已经浏览了this的答案,下面是我的应用程序设置:

不过,这款应用还是进入了风景线。我做错什么了?

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2016-01-02 13:25:22

请检查Info.plist的“支持的接口方向”。它必须显示肖像以满足你的要求。有时,在常规选项卡中,它不会被更新为项目设置。如果你在这里发现景观方向,然后移除它。

代码语言:javascript
运行
复制
<key>UISupportedInterfaceOrientations</key>
<array>
    <string>UIInterfaceOrientationPortrait</string>
</array>

票数 5
EN

Stack Overflow用户

发布于 2016-01-02 16:55:02

iOS9中存在某种bug。它完全忽略了plist文件方向设置。因此,我必须将这段代码添加到我的每个UIViewControllers中,以获得肖像画方向。

代码语言:javascript
运行
复制
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    if (interfaceOrientation == UIInterfaceOrientationPortrait)
    {
        return YES;
    }
    else
    {
        return NO;
    }
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationPortrait;
}

#if __IPHONE_OS_VERSION_MAX_ALLOWED < 90000
- (NSUInteger)supportedInterfaceOrientations
#else
- (UIInterfaceOrientationMask)supportedInterfaceOrientations
#endif
{
    return UIInterfaceOrientationMaskPortrait;
}
票数 2
EN

Stack Overflow用户

发布于 2016-01-04 04:23:36

看来我发现了问题。当我查看我的info.plist的来源时,我发现:

代码语言:javascript
运行
复制
<key>UISupportedInterfaceOrientations</key>
<array>
    <string>UIInterfaceOrientationPortrait</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
    <string>UIInterfaceOrientationPortrait</string>
    <string>UIInterfaceOrientationPortraitUpsideDown</string>
    <string>UIInterfaceOrientationLandscapeLeft</string>
    <string>UIInterfaceOrientationLandscapeRight</string>
</array>

不知道UISupportedInterfaceOrientations~ipad密钥是如何产生的。当作为属性列表查看时,最初不会显示它,但是在作为源代码打开并保存后,它将开始显示在属性列表中。

此外,现在似乎有办法在常规选项卡中设置此选项卡。感谢SamBtechnerd让我走上了正确的道路。

PS:我不确定这是一个bug还是预期的行为,所以我欢迎任何关于这方面的见解。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34566240

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档