加载视图后如何从横向旋转到纵向?
问题描述:
我正在为一个项目的模块工作,当我得到它时,屏幕处于横向模式.我必须加载一个新视图,然后切换到纵向模式.尽管这看起来很简单,但是我还找不到一个简单的解决方案.这是我尝试过的:
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.