我有一个 View Controller 及其 View ,仅支持 iPad 中的横向。
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if (interfaceOrientation == UIInterfaceOrientationPortrait)
return NO;
else
return YES;
}
但我有一个电影播放器的 View ,只需要纵向显示。所以在这个 View 中我这样做:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if (interfaceOrientation == UIInterfaceOrientationPortrait)
return YES;
else
return NO;
}
我的问题是,如果我在第一个 View Controller 中将纵向设置为“否”,那么我的第二个 View Controller 将永远不会旋转到纵向。第二个 View Controller 被添加为第一个 View Controller 的 subview 。如何使 View 1 不旋转为纵向,但使 View 2 不旋转为横向。该应用程序用于演示目的,因此我实际上只是在寻找有关此应用程序的技术答案。
最佳答案
我认为添加为 subview 时这是不可能的。尝试将新 View 推送到不可见的 UINavigationController 堆栈上以实现您的目标。当从第一个 View 转到第二个 View 时,这将起作用,但是当弹出第二个 vc 时,让第一个 View 旋转回原来的位置是非常棘手的,因为苹果不希望你这样做这。这是一个非常非常黑的技巧,可以强制它回到流行状态:
-(void)viewDidAppear:(BOOL)animated {
UIViewController *c = [[UIViewController alloc] init];
[self presentModalViewController:c animated:NO];
[self dismissModalViewControllerAnimated:NO];
[c release];
}
关于iphone - iOS 阻止某些 View 中的旋转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7196300/