2011-03-30 35 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 
}