문제

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?

도움이 되었습니까?

해결책 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;

다른 팁

-(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];
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top