不同观点的取向不同? [英] Different Orientation for Different Views?

查看:69
本文介绍了不同观点的取向不同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个在纵向视图中具有界面的iOS应用程序.

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

但是,当显示Web内容时,我希望视图以横向格式显示,因为我希望网站测试最初显示为更大而无需用户缩放.

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?

谢谢.

推荐答案

似乎只想将方向强制为横向模式.
这是MyViewController.h中的解决方案
将此代码添加到MyViewController的@interface

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

然后在实现文件(MyViewController.m)中 将此代码添加到viewWillAppear中:

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

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

这将迫使设备向左(或向右视情况而定)进入横向模式.
如果要在离开视图控制器后返回纵向模式,请在viewWillDisappear中添加以下代码:

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];

最终实现shouldAutorotateToInterfaceOrientation:强制视图向左或向右(或同时向两个方向)进入横向模式

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);
}

希望这会有所帮助:3

hope this helps :3

这篇关于不同观点的取向不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆