问题
Good evening all! I am developing an application in Portait orientation and i was wander if there is a way for me to change the orientation of only one view to landspace left without messing with the rest of the app.
I tried returning
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
//return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
but with no luck... In IB the orientation for the View controller is set to landscape but when i run the app, it keeps appearing in portrait mode... Also tried setting the
[[UIApplication sharedApplication]setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft animated:NO];
with no luck...
Any help will be greatly appreciated.
Thank you.
回答1:
The only thing that worked for me was using
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
in my ViewController and presenting it with presentModalViewController. This forces the View to stay in landscape.
回答2:
You can manually set the transform of the view to rotate it. For example, to rotate 90 degrees:
view.transform = CGAffineTransformMakeRotation( M_PI / 2 );
回答3:
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight];
Write in your Event.
来源:https://stackoverflow.com/questions/10316683/force-interface-orientation-landscape-on-a-viewcontroller-when-the-rest-of-the-a