简体   繁体   English

横向模式仅适用于iPhone或iPad

[英]Landscape Mode ONLY for iPhone or iPad

I want to create an application that doesn't use Portrait mode. 我想创建一个不使用纵向模式的应用程序。

I am not sure if I need to edit the plist or have code in addition to the plist 我不确定是否需要编辑plist或者除了plist之外还有代码

Code found here 代码在这里找到

Launching in Landscape Mode 以横向模式启动

Applications in iPhone OS normally launch in portrait mode to match the orientation of the Home screen. iPhone OS中的应用程序通常以纵向模式启动,以匹配主屏幕的方向。 If you have an application that runs in both portrait and landscape modes, your application should always launch in portrait mode initially and then let its view controllers rotate the interface as needed based on the device's orientation. 如果您的应用程序在纵向和横向模式下运行,则应用程序应始终以纵向模式启动,然后让其视图控制器根据设备的方向根据需要旋转界面。 If your application runs in landscape mode only, however, you must perform the following steps to make it launch in a landscape orientation initially. 但是,如果应用程序仅以横向模式运行,则必须执行以下步骤以使其最初以横向方向启动。

  • In your application's Info.plist file, add the UIInterfaceOrientation 在应用程序的Info.plist文件中,添加UIInterfaceOrientation
    key and set its value to the 键并将其值设置为
    landscape mode. 景观模式。 For landscape 对于景观
    orientations, you can set the value 方向,你可以设置值
    of this key to 这个关键的
    UIInterfaceOrientationLandscapeLeft
    or 要么
    UIInterfaceOrientationLandscapeRight.

  • Lay out your views in landscape mode and make sure that their autoresizing options are set correctly. 在横向模式下布置视图,并确保正确设置其自动调整大小选项。

  • Override your view controller's shouldAutorotateToInterfaceOrientation: method and return YES only for the 覆盖视图控制器的shouldAutorotateToInterfaceOrientation:方法并仅返回YES
    desired landscape orientation and NO 理想的景观定位和NO
    for portrait orientations. 用于纵向方向。

To make your app landscape mode only , you should use "Supported Interface Orientations". 为了让您的应用程序风景模式而已 ,你应该使用“支持的界面取向”。 ( Targets -> YourApp -> Supported Interface Orientations -> Landscape Left & Right ) Targets -> YourApp -> Supported Interface Orientations -> Landscape Left & Right

支持的接口方向

You should also set the app's orientation in your app's Info.plist file ( 您还应该在应用的Info.plist文件中设置应用的方向( Info.plist文件 ) by appending the Supported interface orientations key with the values Landscape (left home button) and Landscape (right home button) . )通过附加Supported interface orientations键,其值为Landscape (left home button)Landscape (right home button) 行的

You may use willRotateToInterfaceOrientation and/or didRotateFromInterfaceOrientation to handle orientation changes. 您可以使用willRotateToInterfaceOrientation和/或didRotateFromInterfaceOrientation来处理方向更改。


shouldAutorotateToInterfaceOrientation is deprecated from iOS 6 and out. shouldAutorotateToInterfaceOrientation已从iOS 6退出。

Returning UIDeviceOrientationLandscapeLeft/Right for shouldAutorotateToInterfaceOrientation should make your app "landscape": shouldAutorotateToInterfaceOrientation返回UIDeviceOrientationLandscapeLeft/Right应使您的应用程序“横向”:

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

Also may also change your app's Info.plist and View Orientation (as explained above). 也可以更改您的应用的Info.plistView Orientation (如上所述)。


Additionally, I recommend changing your view's orientation to Landscape in the Attributes Inspector . 此外,我建议在“ 属性”检查器中将视图的方向更改为“ Landscape ”。 景观

You could also just shorten it all to 你也可以缩短它

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}

edit the plist to only support landscape, then make sure that in every uiviewcontroller/uitabbar etc., in the shouldAutoRotateToInterfaceOrientation , the return says return ((interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || (interfaceOrientation == UIInterfaceOrientationLandscapeRight)); 编辑的plist仅支持风景,然后确保在每一个的UIViewController / uitabbar等,在shouldAutoRotateToInterfaceOrientationreturnreturn ((interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || (interfaceOrientation == UIInterfaceOrientationLandscapeRight)); .

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM