iOS 6在dismissModalViewController之后恢复方向

MB.*_*MB. 3 ios ios6

我有一个UITabBarViewController纵向模式,我modalViewController在那里推进景观.当我按下模态时,旋转会变为横向,但是当我将其关闭时,方向仍保留在横向中而不是恢复为纵向.

码:

a CustomUINavigationController为横向模式:

- (BOOL)shouldAutorotate
{
  return [[self.viewControllers lastObject] shouldAutorotate];
}

- (NSUInteger)supportedInterfaceOrientations
{
  return [[self.viewControllers lastObject] supportedInterfaceOrientations];
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
  return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
}
Run Code Online (Sandbox Code Playgroud)

uitabbarcontroller

- (BOOL)shouldAutorotate
{
  if ([self inModal]) {
    UINavigationController *nav = (UINavigationController *)self.modalViewController;
    return [[nav.viewControllers lastObject] shouldAutorotate];
  } else {
    return NO;
  }
}

-(NSUInteger)supportedInterfaceOrientations
{
  if ([self inModal]) {
    UINavigationController *nav = (UINavigationController *)self.modalViewController;
    return [[nav.viewControllers lastObject] supportedInterfaceOrientations];
  } else {
    return UIInterfaceOrientationPortrait;
  }    
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
  if ([self inModal]) {
    UINavigationController *nav = (UINavigationController *)self.modalViewController;
    return [[nav.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
  } else {
    return UIInterfaceOrientationPortrait;
  }
}

- (BOOL)inModal
{
  if (self.modalViewController && [self.modalViewController isKindOfClass:[UINavigationController class]]) {
    return YES;
  } else {
    return NO;
  }    
}
Run Code Online (Sandbox Code Playgroud)

如果我将shouldRotate设置为YES,则会出现错误:*由于未捕获的异常'UIApplicationInvalidInterfaceOrientation'而终止应用程序,原因:'支持的方向与应用程序没有共同的方向,并且shouldAutorotate返回YES.即使我在UISupportedDeviceOrientations中设置了两个方向.

flo*_*vdu 6

我认为你的问题是由这一行造成的(你的代码中有两次):

return UIInterfaceOrientationPortrait;
Run Code Online (Sandbox Code Playgroud)

我正在尝试做s.th. 类似于你试图实现的,并在此问我的问题:iOS 6自动轮换问题 - supportedInterfaceOrientations返回值不受尊重

您的代码的问题在于这两种方法不返回接口方向,而是返回一个掩码,该掩码在其位中编码允许或首选方向的组合.

试试这个:

return UIInterfaceOrientationMaskPortrait;
Run Code Online (Sandbox Code Playgroud)

UIInterfaceOrientationPortrait 据我所知,它被映射为0,因此被解释为一组空接口方向(无).