Before you could mark my question as duplicate or vote down please read the question carefully.
I wanted to make my app compatible for both landscape and portrait mode.
Brief idea about the app : I have a table and i navigate to another view on click of its row
i came across this link :
I used the accepted answer on this link
Problem 1 : Initially if i load the app in landscape mode the table appears to be in the left corner.That is it does not changes its frame.
Problem 2 : If i load the app in Portrait mode and then switch to landscape mode then it works great, BUT when i click a row -> navigate to another view -> and again i pop from that view to come to table view, the table again appears to be in the left side corner, similar to problem one.
What I Tried :
1) I tried to check the code for orientation in viewDidLoad instead of viewWillAppear : No change
2) I tried to check the code for orientation in viewDidAppear instead of viewWillAppear :The table frame change and both the problems is solved but it takes a while for the table to change frame. That is , it still appears on the left corner,shrinked, and after say 1-2 seconds it expands to appear what we want.
What I Think : Is there a problem in writing the code (to check orientation) in viewWillAppear ??
To your surprise the same code is working good for iPhone 4. Only giving problem for iPhone5
Here is what my code looks like :
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:YES];
UIInterfaceOrientation statusBarOrientation = [[UIApplication sharedApplication] statusBarOrientation];
if(UIInterfaceOrientationIsPortrait(statusBarOrientation))
{
[self ArrangeControllsFor_Protrate];
}
else
{
[self ArrangeControllsFor_LandScape];
}
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
switch (interfaceOrientation) {
case UIInterfaceOrientationPortrait:
case UIInterfaceOrientationPortraitUpsideDown:
//[self ArrangeControllsFor_Protrate];
[self performSelector:@selector(ArrangeControllsFor_Protrate) withObject:Nil afterDelay:0.005f];
return YES;
break;
case UIInterfaceOrientationLandscapeLeft:
case UIInterfaceOrientationLandscapeRight:
[self performSelector:@selector(ArrangeControllsFor_LandScape) withObject:Nil afterDelay:0.005f];
return YES;
break;
}
}
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
//switch ([UIApplication sharedApplication].statusBarOrientation) {
switch (toInterfaceOrientation) {
case UIInterfaceOrientationPortrait:
case UIInterfaceOrientationPortraitUpsideDown:
//[self ArrangeControllsFor_Protrate];
[self performSelector:@selector(ArrangeControllsFor_Protrate) withObject:Nil afterDelay:0.005f];
break;
case UIInterfaceOrientationLandscapeLeft:
case UIInterfaceOrientationLandscapeRight:
[self performSelector:@selector(ArrangeControllsFor_LandScape) withObject:Nil afterDelay:0.005f];
break;
}
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAll;
}
-(BOOL)shouldAutorotate
{
return YES;
}
-(void)ArrangeControllsFor_Protrate
{
NSLog(@"Portrait Mode");
if([UIScreen mainScreen].bounds.size.height == 568) {
}
else {
// Table genera is table and image gener is image.
[self.tableGener setFrame:CGRectMake(10, 50, 300, 418)];
[self.imageGener setFrame:CGRectMake(0, 0, 320, 480)];
}
}
-(void)ArrangeControllsFor_LandScape
{
if([UIScreen mainScreen].bounds.size.height == 568) {
[self.tableGener setFrame:CGRectMake(30, 43, 506, 310)];
[self.imageGener setFrame:CGRectMake(0, 0, 568, 320)];
}
else {
[self.tableGener setFrame:CGRectMake(30, 43, 418, 300)];
[self.imageGener setFrame:CGRectMake(0, 0, 480, 320)];
}
}