I recently had some success using sub views for rotating from portrait to landscape in Xcode 4.5 (iOS 6). Now that the rotation is working, and I can design separate views for portrait and landscape I have run into another problem.
When the app opens in portrait, everything is fine. But when I push a button to navigate to a new screen. the landscape view is showing over top of the portrait view. If I rotate the simulator to landscape then back to portrait, it loads the portrait view.
Everything works as it should in landscape view. This only happens in Portrait view.
in my .h file I have this:
@interface ViewController : UIViewController{
IBOutlet UIView *portraitView;
IBOutlet UIView *landscapeView;
}
//rotate views
@property (nonatomic, retain) IBOutlet UIView *portraitView;
@property (nonatomic, retain) IBOutlet UIView *landscapeView;
and in my .m file i have this:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didRotate:) name:UIDeviceOrientationDidChangeNotification object:nil];
[self.view addSubview:portraitView];
[self.view addSubview:landscapeView];
}
-(void)didRotate:(NSNotification *)notification
{
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
if (orientation == UIDeviceOrientationPortrait)
{
portraitView.hidden = NO;
landscapeView.hidden = YES;
}
else if (orientation == UIDeviceOrientationLandscapeLeft)
{
portraitView.hidden = YES;
landscapeView.hidden = NO;
}
else if(orientation == UIDeviceOrientationLandscapeRight)
{
portraitView.hidden = YES;
landscapeView.hidden = NO;
}
}
I also have one xib file with three views, a main/blank view that contains all the code and a portrait and landscape view connected to the appropriate outlets.
Probably something simple!
Thanks.