Guest User

Untitled

a guest
Jul 20th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. if ([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationPortrait)
  2. {
  3. CGRect statusBarFrame = [[UIApplication sharedApplication] statusBarFrame];
  4.  
  5. [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO];
  6.  
  7.  
  8. UIScreen *screen = [UIScreen mainScreen];
  9. CGRect newBounds = CGRectMake(0, 0, screen.bounds.size.height, screen.bounds.size.width - statusBarFrame.size.height);
  10.  
  11.  
  12.  
  13. self.navigationController.view.bounds = newBounds;
  14. self.navigationController.view.center = CGPointMake(newBounds.size.height / 2.0, newBounds.size.width / 2.0);
  15. self.navigationController.view.transform = CGAffineTransformConcat(self.navigationController.view.transform, CGAffineTransformMakeRotation(degreesToRadian(90)));
  16. self.navigationController.view.center = window.center;
  17. }
  18.  
  19. You will try this code.
  20.  
  21. 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.
  22.  
  23. #define degreesToRadians(x) (M_PI * x / 180.0)
  24.  
  25. - (void)viewWillAppear:(BOOL)animated
  26. {
  27.  
  28. [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight];
  29.  
  30. CGRect newBounds = CGRectMake(0, 0, 480, 320);
  31. self.navigationController.view.bounds = newBounds;
  32. self.navigationController.view.center = CGPointMake(newBounds.size.height / 2.0, newBounds.size.width / 2.0);
  33.  
  34. self.navigationController.view.transform = CGAffineTransformMakeRotation(degreesToRadians(90));
  35.  
  36. [super viewWillAppear:animated];
  37. }
  38.  
  39. - (void)viewWillDisappear:(BOOL)animated
  40. {
  41. self.navigationController.view.transform = CGAffineTransformIdentity;
  42. self.navigationController.view.transform = CGAffineTransformMakeRotation(degreesToRadians(0));
  43. self.navigationController.view.bounds = CGRectMake(0.0, 0.0, 320.0, 480.0);
  44.  
  45. [super viewWillDisappear:animated];
  46. }
Add Comment
Please, Sign In to add comment