I do the orientation checking dynamically in iOS 5.x as 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 did the below code but thats not working:
-(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 can I check the interface oriention in iOS 6 just like I did in iOS 5.x?
Thanks
You can use the viewWillLayoutSubviews
method, where you check the orientation whith
[[UIApplication sharedApplication] statusBarOrientation];
and set your frames accordingly.
Hope this helps!
Try to do the check in this method
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)orientation
duration:(NSTimeInterval)duration
Edit:
Use this:
BOOL isInPortrait = UIDeviceOrientationIsPortrait([[UIDevice currentDevice] orientation]);
Combined Levi's and Nikola Kirev's answers and now the code is working properly. Thanks both of you. Here is the code for others to reference :
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;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With