Guest User

Untitled

a guest
Aug 15th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. ViewController orientation change
  2. - (void)viewDidLoad
  3. {
  4. [super viewDidLoad];
  5. // Do any additional setup after loading the view from its nib.
  6. Storage *strg = [Storage sharedStorage];
  7.  
  8. if ([strg.orient intValue] == 2)
  9. {
  10. [[UIApplication sharedApplication] setStatusBarOrientation:
  11. UIInterfaceOrientationLandscapeRight];
  12.  
  13. UIScreen *screen = [UIScreen mainScreen];
  14. CGFloat screenWidth = screen.bounds.size.width;
  15. CGFloat screenHeight = screen.bounds.size.height;
  16. UIView *navView = [[self navigationController] view];
  17. navView.bounds = CGRectMake(0, 0, screenHeight, screenWidth);
  18. navView.transform = CGAffineTransformIdentity;
  19. navView.transform = CGAffineTransformMakeRotation(1.57079633);
  20. navView.center = CGPointMake(screenWidth/2.0, screenHeight/2.0);
  21. [UIView commitAnimations];
  22. }
  23. if ([strg.orient intValue] == 1)
  24. {
  25. [[UIApplication sharedApplication] setStatusBarOrientation:
  26. UIInterfaceOrientationLandscapeLeft];
  27.  
  28. UIScreen *screen = [UIScreen mainScreen];
  29. CGFloat screenWidth = screen.bounds.size.width;
  30. CGFloat screenHeight = screen.bounds.size.height;
  31. UIView *navView = [[self navigationController] view];
  32. navView.bounds = CGRectMake(0, 0, screenHeight, screenWidth);
  33. navView.transform = CGAffineTransformIdentity;
  34. navView.transform = CGAffineTransformMakeRotation(4.71238898);
  35. navView.center = CGPointMake(screenWidth/2.0, screenHeight/2.0);
  36. [UIView commitAnimations];
  37. }
  38. }
  39.  
  40. [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(deviceDidRotateSelector:) name: UIDeviceOrientationDidChangeNotification object: nil];
  41.  
  42. -(void)deviceDidRotateSelector:(NSNotification*) notification {
  43. // respond to rotation here
  44. }
  45.  
  46.  
  47. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
  48. //Return YES for supported orientations
  49. return YES;
  50. }
Add Comment
Please, Sign In to add comment