TabBarController中的ModalViewController旋转问题

问题描述 投票:1回答:1

我不太清楚为什么会遇到这个问题,但我…基本上,我在其中一个选项卡中有一个带navigationController的Tabr条形控制器。在此特定选项卡中,我希望用户能够旋转设备并看到完全不同的视图,不是旋转原始视图!

为了实现此功能(在全屏模式下),我有一个LandscapeViewController,当设备横向放置时,会以模态方式显示。当我出现modalViewController

时出现问题

LandscapeViewController中,我还检查方向,因此当用户返回纵向模式时,我可以消除自我。但是,当我展示它时,我得到一个回调,说它正在进入纵向模式,这完全搞砸了!

这里是代码和日志语句,以阐明正在发生的事情。

PortraitViewController

(void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {

    [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
    if(toInterfaceOrientation == UIInterfaceOrientationPortrait || toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown){
  NSLog(@"Norm going Portrait");

  [self changeTheViewToPortrait:YES andDuration:duration];

    }
    else if(toInterfaceOrientation == UIInterfaceOrientationLandscapeRight || toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft){
  NSLog(@"Norm going Landscape");
  [self changeTheViewToPortrait:NO andDuration:duration];
    }
}


(void) changeTheViewToPortrait:(BOOL)portrait andDuration:(NSTimeInterval)duration {

    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:5.];

    if(portrait){ 
  NSLog(@"dismissed");
  [self dismissModalViewControllerAnimated:NO];
    }
    else{ 
  NSLog(@"presented");
  LandscapeOverviewViewController *land = [[LandscapeOverviewViewController alloc]initWithNibName:@"LandscapeOverviewViewController" bundle:nil];
  land.delegate = self;
  [self presentModalViewController:land animated:NO]; 
  [land release];
    }

    [UIView commitAnimations];
}

LandscapeViewController

 (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{

    [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
    if(toInterfaceOrientation == UIInterfaceOrientationPortrait || toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown){
  NSLog(@"Modal is going Portrait");
  [self changeTheViewToPortrait:YES andDuration:duration];

    }
    else if(toInterfaceOrientation == UIInterfaceOrientationLandscapeRight || toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft){
  NSLog(@"Modal is going Landscape");

  [self changeTheViewToPortrait:NO andDuration:duration];
    }
}

 (void) changeTheViewToPortrait:(BOOL)portrait andDuration:(NSTimeInterval)duration{

    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:duration];

    if(portrait){ 
  NSLog(@"calling delegate to dismiss");
  [delegate landscapeViewController:self didRotateBack:(YES)]; 
    }

    [UIView commitAnimations];
}

这是日志文本:

常去风景

2010-08-24 15:29:40.024 App [32461:207]提出

2010-08-24 15:29:40.026 App [32461:207]模态正在进行肖像

2010-08-24 15:29:40.026 App [32461:207]呼叫代表以将其撤职

2010-08-24 15:29:40.027 App [32461:207]代表叫来

如您所见,当我纵向旋转时,我会通过显示landscapevc来做正确的事情,但随后它认为它是纵向并尝试关闭。

谁能看到我要去哪里了吗? (并且对此进行了详细的说明,但是否则代码的格式将无法正常工作。)

iphone cocoa-touch uitabbarcontroller modalviewcontroller screen-rotation
1个回答
1
投票

您是否已在景观视图控制器中实现了shouldAutorotateToInterfaceOrientation:方法?否则,该视图控制器将被迫停留在纵向模式,这将依次触发您的解雇代码。

值得注意的是,有时将视图控制器以特定方向添加到窗口中,然后旋转。相对于当前旋转,检查willRotate传递给您的方向是值得的。我已经有一段时间没有对此进行验证了,但是在2.x后期/3.0天内初期,这很普遍。

© www.soinside.com 2019 - 2024. All rights reserved.