Getting current interface orientation in iOS 6

I am dynamically checking orientation in iOS 5.x, as shown below:

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { if(interfaceOrientation == UIInterfaceOrientationPortrait||interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) { self.viewProfile.frame = CGRectMake(238, 612, 295, 73); // some more settings } else { self.profileNew.frame = CGRectMake(374, 540, 295, 58); // some more settings } return YES; } 

For iOS 6, I made the code below, but it doesn’t work:

 -(BOOL)shouldAutorotate{ return YES; } -(NSInteger)supportedInterfaceOrientations { if (UIDeviceOrientationIsPortrait([UIDevice currentDevice].orientation)) { self.viewProfile.frame = CGRectMake(238, 612, 295, 73); // some more settings } else { self.profileNew.frame = CGRectMake(374, 540, 295, 58); // some more settings } return UIInterfaceOrientationMaskAll; } 

How to check the orientation of the interface in iOS 6 in the same way as in iOS 5.x?

thanks

+7
source share
4 answers

You can use the viewWillLayoutSubviews method, where you check the orientation

[[UIApplication sharedApplication] statusBarOrientation];

and set your frames accordingly.

Hope this helps!

+9
source

Try this method.

 - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)orientation duration:(NSTimeInterval)duration 

Edit:

Use this:

 BOOL isInPortrait = UIDeviceOrientationIsPortrait([[UIDevice currentDevice] orientation]); 
+4
source

The combined answers are Levy and Nikola Kirev, and now the code works correctly. Thanks to both of you. Here is the code for other links:

For iOS 6:

  -(BOOL)shouldAutorotate{ return YES; } -(NSInteger)supportedInterfaceOrientations{ if (UIDeviceOrientationIsPortrait([[UIApplication sharedApplication] statusBarOrientation])) { self.viewProfile.frame = CGRectMake(238, 612, 295, 73); //other codes } else { self.viewProfile.frame = CGRectMake(374, 462, 295, 58); //other codes } return UIInterfaceOrientationMaskAll; } - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)orientation duration:(NSTimeInterval)duration{ if (UIDeviceOrientationIsPortrait(orientation)) { self.viewProfile.frame = CGRectMake(238, 612, 295, 73); //other codes self.profileNew.frame = CGRectMake(238, 713, 295, 73); } else { self.viewProfile.frame = CGRectMake(374, 462, 295, 58); //other codes } } 

For iOS 5.x and 4.x

 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { if(interfaceOrientation == UIInterfaceOrientationPortrait||interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) { self.viewProfile.frame = CGRectMake(238, 612, 295, 73); //other codes } else { self.viewProfile.frame = CGRectMake(374, 462, 295, 58); //other codes } return YES; } } 
+1
source

Try the following:

 UIInterfaceOrientation orientation = [[UIDevice currentDevice] orientation] 
0
source

All Articles