iOS - 将特定的 UIViewController 锁定到特定的方向 [英] iOS - Lock a specific UIViewController to a specific orientation
问题描述
我的应用程序支持每 4 个方向,我在 LandscapeRight
中有一个 UIViewController
.我正在使用 UINavigationController
来推送那个 UIViewController
,我希望 UIViewController
只在 UIInterfaceOrientationLandscapeRight
中,但是当我旋转时手机,它切换回其他方向.
My application supports every 4 orientation, I have a UIViewController
which is in LandscapeRight
.
I am using UINavigationController
to push that UIViewController
, i want that UIViewController
to be only in UIInterfaceOrientationLandscapeRight
but when I rotate the phone, it switches back to other Orientation.
-(BOOL)shouldAutorotate{
return NO;
}
-(NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationLandscapeRight;
}
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
return UIInterfaceOrientationLandscapeRight;
}
推荐答案
只删除那些 shouldAutorotate、supportedInterfaceOrientations 和 preferredInterfaceOrientationForPresentation.
just remove those shouldAutorotate, supportedInterfaceOrientations and preferredInterfaceOrientationForPresentation.
并将其添加到您只想显示横向的视图控制器中.
and add this to the viewcontroller you want to display landscape only.
-(void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
[[UIDevice currentDevice] setValue:
[NSNumber numberWithInteger: UIInterfaceOrientationLandscapeLeft]
forKey:@"orientation"];
}
实际上,这是来自一个类似的问题,这里有解决方案.如何在 iOS 8 中强制视图控制器方向?
actually, this is from a similar question with solution here. How to force view controller orientation in iOS 8?
这篇关于iOS - 将特定的 UIViewController 锁定到特定的方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!