加载视图后如何从横向旋转到纵向? [英] How do I rotate from landscape to portrait upon loading a view?

查看:67
本文介绍了加载视图后如何从横向旋转到纵向?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为一个项目的模块工作,当我得到它时,屏幕处于横向模式.我必须加载一个新视图,然后切换到纵向模式.尽管这看起来很简单,但是我还找不到一个简单的解决方案.这是我尝试过的:

I'm working on a module for a project where the screen is in landscape mode when I get it. I have to load a new view, and switch to portrait mode. While this seems simple enough, I have not been able to find a simple solution. Here's what I tried:

[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait];
locationsView =[[LocationsViewController alloc] initWithNibName:@"LocationsViewController" bundle:nil];
[self.view addSubview:locationsView.view];

并没有按照我的需要工作.它将状态栏旋转为纵向模式,但其余视图未旋转.

and that did not work like I needed. It rotated the status bar to portrait mode, but not the rest of the view.

有什么建议吗?

托马斯

推荐答案

做到了:

[[UIApplication sharedApplication] setStatusBarOrientation: UIInterfaceOrientationPortrait];
self.view.transform = CGAffineTransformIdentity;
self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(-90));
    //resize the view
self.view.bounds = CGRectMake(0.0, 0.0, 320, 460);
self.view.center = CGPointMake(240, 140);

locationsView =[[LocationsViewController alloc] initWithNibName:@"LocationsViewController" bundle:nil];
[self.view addSubview:locationsView.view];

并确保在Global.h中定义了degreeToRadian.

And make sure degreesToRadian is defined in global.h.

这篇关于加载视图后如何从横向旋转到纵向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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