Force Interface orientation Landscape on a viewController when the rest of the application is in portrait mode

吃可爱长大的小学妹 提交于 2019-12-11 09:00:41

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!