在 ios 8.1 中将整个应用的视图旋转锁定为横向
Locking View Rotation to Landscape for whole app in ios 8.1
我是 IOS 开发的新手,我正在尝试编写一个用于在 ipad 上部署的应用程序。部分是为了让事情简单,布局明智,并且因为我相信我的用户只会在横向模式下使用该应用程序,所以我希望只允许横向视图,并完全禁用纵向视图。
我在互联网上找到了很多建议来寻找答案。不幸的是,none 它对我有用。我找到的最佳答案是简单地转到 xcode 中的目标,然后在 "deployment info" -> 设备方向下,简单地取消选中 "Portrait" 和 "Upside Down"。从理论上讲,这应该可以解决我的问题,但不幸的是,事实并非如此。视图旋转与纵向模式一样正常。
转到信息选项卡并将初始界面方向设置为横向(左)确实使应用程序至少以横向模式启动,但它并不仅限于该模式。
连加
- (BOOL)shouldAutorotate {
return NO;
}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscape;
}
进入我的主视图似乎没有任何帮助。所以我有点难过。必须有一些设置或某处仍然允许纵向视图。这个问题可能是什么?
如果您查看 AppName-Info.plist 文件,应该有一个名为 'Supported interface orientations'.
的键
您应该删除该词典中的任何纵向值,并确保只包含横向值!
编辑:
在提问者的案例中,他们的问题涉及 AppDelegate 中的一段代码,该代码更改了应用程序支持的方向。
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
/* They had the following:
* return UIInterfaceOrientationMaskAll;
* Which allowed the orientation to rotate to portrait
*/
// This fixed their issue:
return UIInterfaceOrientationMaskLandscape;
}
希望对您有所帮助!
您可以在项目的“常规”选项卡中执行此操作
我是 IOS 开发的新手,我正在尝试编写一个用于在 ipad 上部署的应用程序。部分是为了让事情简单,布局明智,并且因为我相信我的用户只会在横向模式下使用该应用程序,所以我希望只允许横向视图,并完全禁用纵向视图。
我在互联网上找到了很多建议来寻找答案。不幸的是,none 它对我有用。我找到的最佳答案是简单地转到 xcode 中的目标,然后在 "deployment info" -> 设备方向下,简单地取消选中 "Portrait" 和 "Upside Down"。从理论上讲,这应该可以解决我的问题,但不幸的是,事实并非如此。视图旋转与纵向模式一样正常。
转到信息选项卡并将初始界面方向设置为横向(左)确实使应用程序至少以横向模式启动,但它并不仅限于该模式。
连加
- (BOOL)shouldAutorotate {
return NO;
}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscape;
}
进入我的主视图似乎没有任何帮助。所以我有点难过。必须有一些设置或某处仍然允许纵向视图。这个问题可能是什么?
如果您查看 AppName-Info.plist 文件,应该有一个名为 'Supported interface orientations'.
的键您应该删除该词典中的任何纵向值,并确保只包含横向值!
编辑: 在提问者的案例中,他们的问题涉及 AppDelegate 中的一段代码,该代码更改了应用程序支持的方向。
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
/* They had the following:
* return UIInterfaceOrientationMaskAll;
* Which allowed the orientation to rotate to portrait
*/
// This fixed their issue:
return UIInterfaceOrientationMaskLandscape;
}
希望对您有所帮助!
您可以在项目的“常规”选项卡中执行此操作