【发布时间】:2011-02-08 12:28:36
【问题描述】:
我想创建一个不使用纵向模式的应用程序。
我不确定是否需要编辑 plist 或除 plist 之外还有代码
【问题讨论】:
标签: iphone objective-c cocoa-touch uikit ipad
我想创建一个不使用纵向模式的应用程序。
我不确定是否需要编辑 plist 或除 plist 之外还有代码
【问题讨论】:
标签: iphone objective-c cocoa-touch uikit ipad
以横向模式启动
iPhone OS 中的应用程序正常 以纵向模式启动以匹配 主屏幕的方向。如果你 有一个在两者中运行的应用程序 纵向和横向模式,您的 应用程序应始终启动 肖像模式最初,然后让 它的视图控制器旋转 接口根据需要根据 设备的方向。如果你的 应用程序以横向模式运行 但是,您必须执行 以下步骤使其在 最初是横向的。
在应用程序的 Info.plist 文件中,添加
UIInterfaceOrientation
键并将其值设置为
横向模式。景观
方向,您可以设置值
这把钥匙到UIInterfaceOrientationLandscapeLeft
或UIInterfaceOrientationLandscapeRight.在横向模式下布置视图并确保它们的 设置了自动调整大小选项 正确。
覆盖视图控制器的
shouldAutorotateToInterfaceOrientation:方法并仅对
返回 YES 所需的横向方向和NO
用于纵向。
【讨论】:
要使您的应用横向模式仅,您应该使用“支持的界面方向”。
(Targets -> YourApp -> Supported Interface Orientations -> Landscape Left & Right)
您还应该在应用程序的 Info.plist 文件 () 中设置应用程序的方向,方法是在 Supported interface orientations 键后面附加值 Landscape (left home button) 和 Landscape (right home button)。
您可以使用willRotateToInterfaceOrientation 和/或didRotateFromInterfaceOrientation 来处理方向更改。
shouldAutorotateToInterfaceOrientation 已从 iOS 6 及以后弃用。
为shouldAutorotateToInterfaceOrientation 返回UIDeviceOrientationLandscapeLeft/Right 应该使您的应用程序“风景”:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
还可能更改您应用的Info.plist 和View Orientation(如上所述)。
此外,我建议在属性检查器中将视图的方向更改为Landscape。
【讨论】:
你也可以把它全部缩短为
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
【讨论】:
编辑 plist 以仅支持横向,然后确保在每个 uiviewcontroller/uitabbar 等中,在 shouldAutoRotateToInterfaceOrientation 中,return 表示 return ((interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || (interfaceOrientation == UIInterfaceOrientationLandscapeRight));。
【讨论】: