The root controller of the program uses UINavigationController. The following code is used:
1. Add code to appdelegate:
-(NSUInteger) application :( UIApplication *) application supportedInterfaceOrientationsForWindow :( UIWindow *) window
{
Return UIInterfaceOrientationMaskAll;
}
2. Add a category to UINavigationController and add the following code to the implementation file:
-(BOOL) shouldAutorotate
{
Return [[self topViewController] shouldAutorotate];
}
-(NSUInteger) supportedInterfaceOrientations
{
Return [[self topViewController] supportedInterfaceOrientations];
}
-(UIInterfaceOrientation) preferredInterfaceOrientationForPresentation
{
Return [[self topViewController] preferredInterfaceOrientationForPresentation];
}
3. Add a horizontal screen (you can change the direction of the portrait screen ):
-(NSUInteger) supportedInterfaceOrientations {
Return UIInterfaceOrientationMaskLandscapeRight; // you can change it to any direction.
}
-(BOOL) shouldAutorotate {
Return YES;
}
-(BOOL) shouldAutorotateToInterfaceOrientation :( UIInterfaceOrientation) interfaceOrientation {
Return interfaceOrientation = UIInterfaceOrientationLandscapeRight;
}
4. The most important thing is that the navigation controller cannot be used for switching between pages. You must use:
[Self presentViewController: navigationController animated: YES completion: Nil];