Question

I'm trying to achieve the following:

I have two nib files, one in portrait view and one in landscape named WHMainViewController and WHMainLandscapeView, respectively.

I have one UIViewController named WHMainViewController.

I would like to present the WHMainViewController when in portrait view and WHMainLandscapeView when in landscape view.

I've looked into these functions:

-(void)orientationChanged:(NSNotification *)object{ UIDeviceOrientation deviceOrientation = [[object object] orientation];

if (deviceOrientation == UIInterfaceOrientationPortrait ) { 
}
else if (deviceOrientation == UIInterfaceOrientationLandscapeLeft || deviceOrientation ==    UIInterfaceOrientationLandscapeRight) {
}

How should I implement them though?

Was it helpful?

Solution 2

This website provides an excellent tutorial on this issue: http://www.theappcodeblog.com/2011/03/30/orientation-change-tutorial-change-the-view-when-the-orientation-changes/

By setting up two UIViews within the Xib of WHMainViewController.

Then connect two IBOutlets two the two views with one named portraitView and the other as landscapeView.

When the device rotates, update the view accordingly by setting

self.view = self.portraitView;

or

self.view = self.landscapeView;

OTHER TIPS

-(void)orientationChanged:(NSNotification *)object{ UIDeviceOrientation deviceOrientation = [[object object] orientation];

if (deviceOrientation == UIInterfaceOrientationPortrait ) { 
    WHMainViewController *VC = [[WHMainViewController alloc]initWithNibName:@"WHMainViewController" bundle:nil];
    [self.navigationController pushViewController:VC animated:YES];
}
else if (deviceOrientation == UIInterfaceOrientationLandscapeLeft || deviceOrientation ==    UIInterfaceOrientationLandscapeRight) 
{
    WHMainViewController *VC = [[WHMainViewController alloc]initWithNibName:@"WHMainLandscapeView" bundle:nil];
    [self.navigationController pushViewController:VC animated:YES];
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top