2011-03-30 61 views
0

我的應用程序只有一個肖像驅動的GUI,但只有一個部分需要旋轉。 當設備正在旋轉時,我想關閉當前的視圖(控制器?)並將其替換爲完全不同的視圖。 我該怎麼辦?任何示例代碼?替換iPhone上的ViewController旋轉

+0

所以你要加載一個新的viewController? – SNR 2011-03-30 06:57:58

回答

2

您可以只需在文件的.xib相同的UIViewController 2個不同的觀點和需要時它們之間進行切換。

比方說,你在UIViewController的兩種觀點:

  • ViewPortrait
  • ViewLandscape
-(void) willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration 
{ 
    switch (toInterfaceOrientation) 
    { 
     case UIInterfaceOrientationPortrait: 
     case UIInterfaceOrientationPortraitUpsideDown: 
      self.view = self.ViewPortrait; 
      break; 

     case UIInterfaceOrientationLandscapeLeft: 
     case UIInterfaceOrientationLandscapeRight: 
      self.view = self.ViewLandscape;   
      break; 
    } 
} 
0
- (void)didRotate 
{ 
//Create your new view controller here if it doesn't exist. 
//Push or present the view controller 
}