How do I rotate from landscape to portrait upon loading a view?
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:UIInterfaceOrientationP开发者_如何学Cortrait];
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.
Any suggestions?
Thomas
This did it:
[[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];
And make sure degreesToRadian is defined in global.h.
精彩评论