I am using a splitviewcontroller as the rootview of my application. I need to show the login and registration views as a modal view on top of the splitviewcontroller. When i
If I remember correctly, iOS misreports the actual orientation until the first rotation.
Also IIRC, using [[UIApplication sharedApplication] statusBarOrientation]
circumvents this problem.
After removing the login view from the window set the rootviewcontroller direction according to the orientation of device using following code.
#define DegreesToRadians(x) ((x) * M_PI / 180.0)
[LoginviewContoller.view removeFromSuperview]
self.viewController = [[[ExampleViewController alloc] initWithNibName:@"ExampleViewController" bundle:nil] autorelease];
switch(self.viewController.interfaceOrientation)
{
case UIInterfaceOrientationPortrait:
NSLog(@"potrait");
break;
case UIInterfaceOrientationPortraitUpsideDown:
NSLog(@"prtraitdown");
break;
case UIInterfaceOrientationLandscapeLeft:
self.viewController.view.transform =
CGAffineTransformMakeRotation(DegreesToRadians(270));
NSLog(@"lanscapelef");
break;
case UIInterfaceOrientationLandscapeRight:
self.viewController.view.transform = CGAffineTransformMakeRotation(DegreesToRadians(90));
NSLog(@"landcsape righ");
break;
}
[self.window addSubview:self.viewController.view];
It will load the Rootviewcontroller according to the device orientation.