Replacing ViewController on iPhone rotation
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
}
精彩评论