In my application I have 2 views, portraitView and landScapeView. And also my application consists of many views…
-
When I launch the application both landscape and portrait view is getting displayed side by side.
-
When I launch the application in landscapeview the portraitview is getting displayed..later after rotating and coming back the view is getting proper.
The code I am using is given below…so please suggest me what all changes should be done to overcome above problem as mentioned..
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft) {
NSLog(@"LANDSCAPE>>");
portraitView.hidden = YES;
landscapeView.hidden = NO;
UIColor *background = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"bg-ic_landscape.jpg"]];
self.view.backgroundColor = background;
}
else if (interfaceOrientation == UIInterfaceOrientationLandscapeRight){
NSLog(@"LANDSCAPE<<");
portraitView.hidden = YES;
landscapeView.hidden = NO;
UIColor *background = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"bg-ic_landscape.jpg"]];
self.view.backgroundColor = background;
self.view.hidden = NO;
}
else{
portraitView.hidden = NO;
landscapeView.hidden = YES;
NSLog(@"Portrait");
UIColor *background = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"bg-ic.jpg"]];
self.view.backgroundColor = background;
background = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"bg-ic2.jpg"]];
self.view.backgroundColor = background;
}
return YES;
It sounds like your portraitView and landscapeView are both visible on initial launch of the app. The code above is only executed when the orientation changes during runtime. If you do insist on using separate views for portrait and landscape then you’ll need to detect orientation at launch as well and show / hide the views appropriately.