I have a simple Master-Detail application with a MasterViewController and a DetailViewController. Inside of the DetailViewController I have implemented the following code so that when the view is rotated my two buttons are positioned properly.
- (void)willAnimateRotationToInterfaceOrientation:
(UIInterfaceOrientation)toInterfaceOrientation
duration:(NSTimeInterval)duration
{
if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft)
{ firstButton.frame = CGRectMake(20, 240, 50, 50);
secondButton.frame = CGRectMake(390, 240, 50, 50);
}
else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
firstButton.frame = CGRectMake(20, 240, 50, 50);
secondButton.frame = CGRectMake(390, 240, 50, 50);
}
else
{
firstButton.frame = CGRectMake(80, 390, 50, 50);
secondButton.frame = CGRectMake(190, 390, 50, 50);
}
}
If the iPhone isn’t rotated until the DetailViewController is in view, then the buttons are positioned properly. But if the user rotates the iPhone while viewing the MasterViewController table view and then taps an item, when the DetailViewController opens, the buttons are not positioned correctly.
So how can I or where do I position the buttons from the MasterViewController? Thank you for the help!
You can check
interfaceOrientationproperty ofUIViewControllerin your viewDidLoad or viewWillAppear for example: