Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/101.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iOS 6在解除ModalViewController后恢复方向_Ios_Ios6 - Fatal编程技术网

iOS 6在解除ModalViewController后恢复方向

iOS 6在解除ModalViewController后恢复方向,ios,ios6,Ios,Ios6,在纵向模式下,我有一个uitabarviewcontroller,我在横向模式下推一个modalViewController。当我按下该模式时,旋转将变为横向,但当我取消该模式时,方向将保持在横向,而不是恢复为纵向 代码: 横向模式的CustomUINavigationController: - (BOOL)shouldAutorotate { return [[self.viewControllers lastObject] shouldAutorotate]; } - (NSUInte

在纵向模式下,我有一个
uitabarviewcontroller
,我在横向模式下推一个
modalViewController
。当我按下该模式时,旋转将变为横向,但当我取消该模式时,方向将保持在横向,而不是恢复为纵向

代码:

横向模式的
CustomUINavigationController

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

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

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
  return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
}
阿巴斯控制器

- (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;
  }    
}

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

我认为您的问题是由这行代码引起的(代码中有两次):

我现在正在尝试做s.th。与您试图实现的目标类似,并在这里提出了我的问题:

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

试试这个:

return UIInterfaceOrientationMaskPortrait;
据我所知,
ui接口方向纵向
被映射为0,因此被解释为接口方向的空集合(无)

return UIInterfaceOrientationMaskPortrait;