由于在iOS 6中ShouldAutorotateToInterfaceOrientation
已被弃用,而我之前使用它来强制一个特定的视图仅支持竖屏,那么在iOS 6中正确的做法是什么?这仅适用于我的应用程序中的一个区域,所有其他视图都可以旋转。
由于在iOS 6中ShouldAutorotateToInterfaceOrientation
已被弃用,而我之前使用它来强制一个特定的视图仅支持竖屏,那么在iOS 6中正确的做法是什么?这仅适用于我的应用程序中的一个区域,所有其他视图都可以旋转。
我看到了很多答案,但并没有得到关于方向的具体想法和答案,但是看到了链接,理解了方向,并且移除了iOS6中的强制旋转。
http://www.disalvotech.com/blog/app-development/iphone/ios-6-rotation-solution/
我认为这很有帮助。
supportedInterfaceOrientations
和 preferredInterfaceOrientationForPresentation
。使用子类或分类来允许 UINavigationController 和 UITabBarController 类中的 VC 正常工作是很好的解决方案。从横向标签栏控制器启动仅支持纵向的模态视图失败了。如果您需要这样做,那么请使用显示和隐藏非动画模态视图的技巧,但在 viewDidAppear 方法中执行。在 viewDidLoad 或 viewWillAppear 中对我不起作用。
除此之外,上述解决方案都可以正常工作。
只需前往project.plist,然后添加Supported interface orientation,然后仅添加Portrait(底部Home按钮)和Portrait(顶部Home按钮)。
您可以根据项目要求添加或删除方向。
谢谢。
1) 检查您的项目设置和info.plist文件,确保只选择了您想要的方向。
2) 将以下方法添加到您的最顶层视图控制器(导航控制器/标签栏控制器)中:
- (NSUInteger) supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
3) 将以下方法添加到您的应用程序委托中
- (NSUInteger) supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
return UIInterfaceOrientationMaskPortrait;
}
ViewController
的 .m 文件中:- (NSUInteger)supportedInterfaceOrientations
{
//return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft;
return UIInterfaceOrientationMaskPortrait;
}
请查看此处以获取更多信息。