横向模式仅适用于iPhone或iPad

Coc*_*Dev 37 iphone cocoa-touch objective-c uikit ipad

我想创建一个不使用纵向模式的应用程序.

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

Jus*_*ire 47

代码在这里找到

以横向模式启动

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

  • 在应用程序的Info.plist文件中,添加UIInterfaceOrientation
    密钥并将其值设置为
    横向模式.对于横向
    方向,您可以
    将此键的值设置为
    UIInterfaceOrientationLandscapeLeft

    UIInterfaceOrientationLandscapeRight.

  • 在横向模式下布置视图,并确保正确设置其自动调整大小选项.

  • 覆盖视图控制器的 shouldAutorotateToInterfaceOrientation: 方法,仅针对
    所需的横向方向返回YES ,
    针对纵向方向返回NO .


Ale*_*izi 29

为了让您的应用程序风景模式,你应该使用"支持的界面取向".(Targets -> YourApp -> Supported Interface Orientations -> Landscape Left & Right)

支持的接口方向

您还应该在应用程序的Info.plist文件中设置应用程序的方向(Info.plist文件)通过附加Supported interface orientations与所述值的键Landscape (left home button)Landscape (right home button).行的

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


shouldAutorotateToInterfaceOrientationiOS 6开始不推荐使用.

回到UIDeviceOrientationLandscapeLeft/RightshouldAutorotateToInterfaceOrientation应该让你的应用程序的"风景":

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
Run Code Online (Sandbox Code Playgroud)

也可以更改您的应用程序Info.plistView Orientation(如上所述).


此外,我建议Landscape在" 属性"检查器中更改视图的方向.景观


fed*_*est 26

你也可以缩短它

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
Run Code Online (Sandbox Code Playgroud)


jrt*_*c27 10

编辑plist只支持横向,然后确保在每个uiviewcontroller/uitabbar等中shouldAutoRotateToInterfaceOrientation,在returnreturn ((interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || (interfaceOrientation == UIInterfaceOrientationLandscapeRight));.

  • 甚至更短:return(UIInterfaceOrientationIsLandscape(interfaceOrientation)) (5认同)
  • 甚至更好:if(UIInterfaceOrientationIsLandscape(interfaceOrientation)){return YES; }返回NO; (3认同)