开发者

Replacing ViewController on iPhone rotation

开发者 https://www.devze.com 2023-02-20 13:06 出处:网络
My App only has a portrait driven GUI, but there\'s a only section that needs to be rotated. When the device is being rotated I want to dismiss the current View(Controller?) and replace i开发者_如何学

My App only has a portrait driven GUI, but there's a only section that needs to be rotated. When the device is being rotated I want to dismiss the current View(Controller?) and replace i开发者_如何学编程t with a totally different looking one. How can I do? Any example code?


You can simply have 2 Different Views in the same UIViewController in the .xib file and switch between them when needed.

Let's say you have Two views in the 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;
   }
}


- (void)didRotate
{
 //Create your new view controller here if it doesn't exist.
 //Push or present the view controller
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号