amavi
amavi

Reputation: 534

Best practices for navigations in landscape and portrait mode in UINavigationController

I am developing an iPad application which supports both landscape as well as portrait orientation.I am having two different nib files for my rootviewController. Here is the scenario of the issue -
1.Select an item from root view in portait mode, pushes the next view in portrait.
2.Rotate the device
3.Press back button on navigation bar
The view is loaded from the stack is portait view of rootViewController. While device is still in landscape mode.
Please suggest the solution to handle above issue.
Also, please suggest the best practices to follow while handling device rotations.

Upvotes: 1

Views: 433

Answers (3)

iAmitWagh
iAmitWagh

Reputation: 453

You need to check orientation at runtime in method - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

} & change elements of your view according to orientation.

Upvotes: 1

Nitish
Nitish

Reputation: 14123

Use notifications in following methods and set the coordinates in receivedRotate method.

-(void)viewWillAppear:(BOOL)animated
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receivedRotate:) name:UIDeviceOrientationDidChangeNotification object:nil];
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];

}

-(void)viewWillDisappear:(BOOL)animated
{
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIDeviceOrientationDidChangeNotification object:nil];
}

For example in receivedRotate you can set your tableview's coordinates as :

if (orientation == UIDeviceOrientationLandscapeLeft||orientation==UIDeviceOrientationLandscapeRight)
    {
        [tblView reloadData];
        tableX=70.0;

    }
    else
    {
        [tblView reloadData];
        tableX=48.0;
}  

Also call recieveRotate in viewDidLoad which is very important.

Upvotes: 1

Abhijeet Barge
Abhijeet Barge

Reputation: 574

check this method , may be help u...

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations.
return ( 
        interfaceOrientation == UIInterfaceOrientationPortrait 
        || interfaceOrientation == UIInterfaceOrientationLandscapeLeft
        || interfaceOrientation == UIInterfaceOrientationLandscapeRight
        || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown
        );}

or try to set autoresizingMask for controllers hope it will help u.

Upvotes: 1

Related Questions