I have created an application to support all orientations.
Also I have created a table and search bar in viewDidLoad
method (without using xib). I have also written following code to adjust the positioning of table view and search bar.
It works properly when I launch my application in portrait view and when I rotate to landscape view, it adjust the views perfectly.
But when I launch my application in landscape mode, views are not adjusted, instead they take positioning of portrait view. But again when I rotate in portrait and then landscape it works all right.
Also to ensure that correct orientation is captured, I have written NSLog
inside this method, and it shows me the correct value.
Also to ensure that this method (adjustViewsForOrientation
) is called explicitly, I have called the method in viewDidLoad
as well.
[self adjustViewsForOrientation:self.interfaceOrientation];
Here is a rest of code snippet:
- (void) adjustViewsForOrientation:(UIInterfaceOrientation)orientation {
if (orientation == UIInterfaceOrientationLandscapeLeft ||
orientation == UIInterfaceOrientationLandscapeRight) {
aTableView.frame = CGRectMake(705, 220, 320, 280);
sBar.frame=CGRectMake(805, 0, 220, 40);
NSLog(@"inside landscape");
}
else if (orientation == UIInterfaceOrientationPortrait ||
orientation == UIInterfaceOrientationPortraitUpsideDown) {
aTableView.frame = CGRectMake(450, 220, 320, 280);
sBar.frame=CGRectMake(550,3,220,40);
}
}
- (void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
duration:(NSTimeInterval)duration {
// [self adjustViewsForOrientation]
[self adjustViewsForOrientation:toInterfaceOrientation];
NSLog(@"landscap");
}