首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >仅适用于iPhone或iPad的横向模式

问仅适用于iPhone或iPad的横向模式
EN

Stack Overflow用户
提问于 2010-04-16 01:59:55
回答 4查看 38.5K关注 0票数 37

我想创建一个不使用肖像模式的应用程序。

我不确定是否需要编辑plist,或者除了plist之外还需要代码。

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2010-04-16 02:02:29

Code found here

在横向模式下启动

iPhone OS中的应用程序通常以纵向模式启动,以匹配主屏幕的方向。如果你有一个同时在纵向和横向模式下运行的应用程序,你的应用程序最初应该总是在纵向模式下启动,然后让它的视图控制器根据设备的方向根据需要旋转界面。但是,如果您的应用程序仅在横向模式下运行,则必须执行以下步骤才能使其最初以横向方式启动。

  • 在应用程序的Info.plist文件中,添加UIInterfaceOrientation

键,并将其值设置为

横向模式。对于景观

方向,您可以设置该值

此密钥的

UIInterfaceOrientationLandscapeLeft

或

在横向模式下对视图进行UIInterfaceOrientationLandscapeRight.

  • Lay,并确保它们的自动调整大小选项已设置为视图控制器的shouldAutorotateToInterfaceOrientation:方法,并仅为

所需的横向方向和无

对于纵向orientations.

票数 47
EN

Stack Overflow用户

发布于 2012-07-19 03:32:50

要使你的应用程序的横向模式仅支持界面,你应该使用“”。(Targets -> YourApp -> Supported Interface Orientations -> Landscape Left & Right)

​

​

还应在应用程序的Info.plist文件中设置应用程序的方向(

)通过将值Landscape (left home button)和Landscape (right home button)附加到Supported interface orientations密钥。

​

您可以使用willRotateToInterfaceOrientation和/或didRotateFromInterfaceOrientation来处理方向更改。

在iOS 6和更高版本中,shouldAutorotateToInterfaceOrientation已弃用。

为shouldAutorotateToInterfaceOrientation返回UIDeviceOrientationLandscapeLeft/Right应该会让你的应用变得“风景”:

代码语言:javascript
复制
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

也可能改变你的应用的Info.plist和View Orientation (如上所述)。

此外,我建议在属性检查器中将视图的方向更改为Landscape。

​

票数 29
EN

Stack Overflow用户

发布于 2011-07-21 21:27:44

您也可以将所有内容缩短为

代码语言:javascript
复制
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
票数 26
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2647786

复制
相关文章

相似问题

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