I have this iPad application with different NIBs and views. Each view has two NIBs, one for potrait orientation and one for landscape, so i'm searching for a method to programmatically switch NIB for a given UIViewController .
Right now i have this function that i'm using in the willRotateToInterfaceOrientation method of each controller :
void UIHandleRotation( UIViewController *controller, NSString *nibName, UIInterfaceOrientation orientation, BOOL transform ){
double angle = 0.0;
if( orientation == UIInterfaceOrientationPortrait ) {
angle = PI * 2 /* 360° */;
}
else if( orientation == UIInterfaceOrientationLandscapeLeft ){
angle = PI + PI/2 /* 270 ° */;
// Each landscape nib is [nib-name]L
nibName = [NSString stringWithFormat:@"%@L", nibName];
}
[[NSBundle mainBundle] loadNibNamed:nibName owner:controller options:nil];
if( transform ) {
controller.view.transform = CGAffineTransformMakeRotation( angle );
}
}
But it's giving me strange behaviour (ui controls position messed, the outlets are not associated as in interface builder, and so forth).
Am i doing something wrong or there's just a better way to implement this ? Thanks
NOTE: I'm not using a navigation controller, so i can't use this solution Easiest way to support multiple orientations? How do I load a custom NIB when the application is in Landscape?