Iphone 在用户操作上旋转UIViewController

Iphone 在用户操作上旋转UIViewController,iphone,ios,uiviewcontroller,uiinterfaceorientation,Iphone,Ios,Uiviewcontroller,Uiinterfaceorientation,我所拥有的: 我有一个支持纵向和横向的viewcontroller。在横向视图中,我会显示肖像内容的过滤器视图 我需要做什么: 当用户在横向视图中选择过滤器时,我想强制将设备旋转回纵向 我在谷歌上搜索了一下,发现 [[UIDevice currentDevice] setOrientation:UIInterfaceOrientationPortrait]; 这是一个私有API,我不想这样做。(但请原谅我所追求的) 简而言之,在用户操作上,我想强制旋转设备。 文件中有我遗漏的东西吗 任何想法都

我所拥有的:

我有一个支持纵向和横向的viewcontroller。在横向视图中,我会显示肖像内容的过滤器视图

我需要做什么:

当用户在横向视图中选择过滤器时,我想强制将设备旋转回纵向

我在谷歌上搜索了一下,发现

[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationPortrait];
这是一个私有API,我不想这样做。(但请原谅我所追求的)

简而言之,在用户操作上,我想强制旋转设备。 文件中有我遗漏的东西吗

任何想法都会很棒。
Dan

如果有效,您可以尝试使用此功能

-(void)forceFullyPortraitView{
[self.appDel.navigationController.view removeFromSuperview];
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait];
[ [UIApplication sharedApplication].self.delegate.window addSubview:self.appDel.navigationController.view];
self.navigationController.navigationBar.hidden=NO;
}
-(void)forceFullyLandscapeView{
[self.appDel.navigationController.view removeFromSuperview];
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight];
[ [UIApplication sharedApplication].self.delegate.window addSubview:self.appDel.navigationController.view];
self.navigationController.navigationBar.hidden=NO;
}

可以将landScepe设置为右或左

这是从经验中学到的!在
视图中执行此操作。加载:

UIViewController *vc = [[UIViewController alloc] init];
[self presentModalViewControllerAnimated:NO];
[self dismissModalViewControllerAnimated:NO];

它将强制横向,前提是您只为横向返回
shouldAutorotateToInterfaceOrientation
。没有私人API

我认为在代码中强制设备旋转是不可能的。看看这个问题:这是我的想法,但这个问题已经12个月了,所以我希望这已经改变:(我几周前试过了,但也没有找到任何解决方案):/你不应该强迫用户在显示相同的viewController时旋转设备。那里(希望如此)永远不会对此进行任何修复。您可以仅以模态方式呈现新的viewController,使其独立于所有其他现有导航机制(tabBarController、navigationController)因此,允许对方向进行新的限制。这不起作用。这会导致混乱和子视图无法返回其原始位置您的两个方法被称为相同的东西。谢谢,但是这不起作用,除非在viewDidLoad中-我在用户操作后才这样做。(按下按钮)