我想在iOS设备旋转到横向时显示不同的全屏视图,并在设备旋转回风景时返回到之前的视图。我主要通过使用一个视图控制器和两个视图来获得它的工作,然后在 - shouldAutorotateToInterfaceOrientation中将视图控制器的self.view设置为适当的视图。如何在iPhone旋转时推送全屏视图控制器?
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if(((interfaceOrientation == UIInterfaceOrientationLandscapeLeft) ||
(interfaceOrientation == UIInterfaceOrientationLandscapeRight))){
self.view = landscapeView;
}else if(((interfaceOrientation == UIInterfaceOrientationPortrait) ||
(interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown))){
self.view = portraintView;
}
return YES;
}
但是,理想情况下,我希望景观视图具有它自己的单独视图控制器来管理视图。我试着推模态的视图控制器和shouldAutorotateToInterfaceOrientation驳回:,但横向视图控制器不上来的正确方向(但仍认为该设备处于纵向)
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if(((interfaceOrientation == UIInterfaceOrientationLandscapeLeft) ||
(interfaceOrientation == UIInterfaceOrientationLandscapeRight))){
[self presentModalViewController:landscapeViewController animated:YES];
}else if(((interfaceOrientation == UIInterfaceOrientationPortrait) ||
(interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown))){
[self dismissModalViewControllerAnimated:YES];
}
return YES;
}
然后当我回到纵向视图时,它仍然认为设备处于横向状态。
其实我已经忘记了,我试图做的工作在willAnimateRotationToInterfaceOrientation:但我需要做的didRotateToInterfaceOrientation:这样,当我推动视图控制器它将在正确的方向。谢谢! – Austin 2012-03-20 15:41:03