Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if ([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationPortrait)
- {
- CGRect statusBarFrame = [[UIApplication sharedApplication] statusBarFrame];
- [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO];
- UIScreen *screen = [UIScreen mainScreen];
- CGRect newBounds = CGRectMake(0, 0, screen.bounds.size.height, screen.bounds.size.width - statusBarFrame.size.height);
- self.navigationController.view.bounds = newBounds;
- self.navigationController.view.center = CGPointMake(newBounds.size.height / 2.0, newBounds.size.width / 2.0);
- self.navigationController.view.transform = CGAffineTransformConcat(self.navigationController.view.transform, CGAffineTransformMakeRotation(degreesToRadian(90)));
- self.navigationController.view.center = window.center;
- }
- You will try this code.
- Take a look at the function `shouldAutorotateToInterfaceOrientation`: in the UIViewController class. This function returns YES if the orientations is supported by your UIView. If you return YES only to the landscape orientation, then the iPhone will automatically be put in that orientation.
- #define degreesToRadians(x) (M_PI * x / 180.0)
- - (void)viewWillAppear:(BOOL)animated
- {
- [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight];
- CGRect newBounds = CGRectMake(0, 0, 480, 320);
- self.navigationController.view.bounds = newBounds;
- self.navigationController.view.center = CGPointMake(newBounds.size.height / 2.0, newBounds.size.width / 2.0);
- self.navigationController.view.transform = CGAffineTransformMakeRotation(degreesToRadians(90));
- [super viewWillAppear:animated];
- }
- - (void)viewWillDisappear:(BOOL)animated
- {
- self.navigationController.view.transform = CGAffineTransformIdentity;
- self.navigationController.view.transform = CGAffineTransformMakeRotation(degreesToRadians(0));
- self.navigationController.view.bounds = CGRectMake(0.0, 0.0, 320.0, 480.0);
- [super viewWillDisappear:animated];
- }
Add Comment
Please, Sign In to add comment