我想创建一个不使用竖屏模式的应用程序。
我不确定是否需要编辑plist文件或者除了plist文件还需要编写代码。
我想创建一个不使用竖屏模式的应用程序。
我不确定是否需要编辑plist文件或者除了plist文件还需要编写代码。
以横向模式启动
iPhone OS中的应用程序通常会以竖屏模式启动,以匹配主屏幕的方向。如果您的应用程序在竖屏和横屏模式下运行,则应始终以竖屏模式启动,然后让其视图控制器根据设备的方向旋转界面。但是,如果您的应用程序仅在横屏模式下运行,则必须执行以下步骤才能使其最初以横向方向启动。
在应用程序的Info.plist文件中,添加UIInterfaceOrientation键并将其值设置为横向模式。对于横向方向,可以将此键的值设置为UIInterfaceOrientationLandscapeLeft或UIInterfaceOrientationLandscapeRight。
以横向模式布局您的视图,并确保它们的自动调整选项设置正确。
覆盖您的视图控制器的shouldAutorotateToInterfaceOrientation:方法,并仅对期望的横向方向返回YES,对竖向方向返回NO。
目标 -> 您的应用程序 -> 支持的界面方向 -> 左右横向
)
Info.plist
文件中设置应用的方向(Supported interface orientations
键附加到值为 Landscape (left home button)
和 Landscape (right home button)
的值。您可以使用 willRotateToInterfaceOrientation
和/或 didRotateFromInterfaceOrientation
来处理方向更改。
shouldAutorotateToInterfaceOrientation
在iOS 6及以上版本中已被弃用。
返回UIDeviceOrientationLandscapeLeft/Right
以使您的应用程序“横向”:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
同时,您也可以更改应用程序的 Info.plist
和视图方向
(如上所述)。
Landscape
。 你也可以将其简化为
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
编辑plist文件以仅支持横向屏幕,然后确保在每个uiviewcontroller / uitabbar等中,shouldAutoRotateToInterfaceOrientation
方法中的return
语句为 return ((interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || (interfaceOrientation == UIInterfaceOrientationLandscapeRight));
。