Different Orientation for Different Views?

核能气质少年 提交于 2019-12-11 15:32:57

问题


I'm making an iOS application that has an interface in the portrait view.

However, when displaying web content I want the view to display in a landscape format, because I want the website test to display larger initially without the user needing to zoom.

Can I tell the program so present this view only in landscape?

Thank you.


回答1:


looks like you want to force the orientation to landscape mode only..
heres my solution in MyViewController.h
add this code on top of MyViewController's @interface

 //force orientation on device
    @interface UIDevice (PrivateOrientation)
    - (void) setOrientation:(UIInterfaceOrientation)orientation;
    @end

then in the implementation file (MyViewController.m) add this code inside viewWillAppear:

//change orientation of device
[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeLeft];

this will force the device orientation to landscape mode left (or right depending what you want)
if you want to go back to portrait mode after leaving the viewcontroller add this code inside viewWillDisappear:

//change orientation of device
[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationPortrait];

finally implement shouldAutorotateToInterfaceOrientation: to force the view into landscape mode left or right (or both)

// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

hope this helps :3



来源:https://stackoverflow.com/questions/8903230/different-orientation-for-different-views

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