因此,像许多其他人一样,我遇到了一个问题,即只有一个或两个视图控制器支持纵向和横向界面方向,否则只能在纵向应用程序中。在 iOS 6 之前一切正常,但突然自动旋转停止工作。多亏了这里的一些好问题,我能够通过让初始 navController 返回单个 topViewController 对 shouldAutorotate 的偏好来解决该问题:
- (BOOL)shouldAutorotate
{
return self.topViewController.shouldAutorotate;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAll;
}
但是,我偶然发现了一个新问题。根 vc (viewController A) 不应该自动旋转并且应该只支持纵向。导航堆栈中的 ViewController B 支持纵向和横向。如果我在viewController B中,并且在横向中,然后触摸“返回”以将视图弹出回viewController A ... vc A加载横向,它甚至不应该支持,并且不会旋转回纵向,因为vc A 的 shouldAutorotate 设置为 NO...
任何有关如何处理此问题的想法将不胜感激。我最初的想法是用手动方法覆盖vc B的“后退”按钮,如果视图处于横向状态,首先强制旋转回纵向......然后将视图控制器弹出回vc A......但我不知道如何以编程方式强制旋转。有任何想法吗?
以下是vc A中的接口方法:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return NO;
}
-(BOOL)shouldAutorotate
{
return NO;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationPortrait;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return UIInterfaceOrientationPortrait;
}
这是它们在 vc B 中的内容:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
-(BOOL)shouldAutorotate
{
return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAllButUpsideDown;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return UIInterfaceOrientationPortrait;
}