我想在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