0

I am working on a project where I want to replace the icons based on the orientation of the device without allowing the viewController to rotate. I have several viewController that are allowed to rotate and others, specified in my navigation controller that are not allowed to rotate.

This implementation works exactly how i want it to.

Code in my navigation controller:

- (BOOL)shouldAutorotate
{
    id currentViewController = self.topViewController;

    if ([currentViewController isKindOfClass:[ChimpTabBarController class]]) {
        ChimpTabBarController *tabbarController = (ChimpTabBarController*)currentViewController;

        if (tabbarController.selectedIndex == 0){
            return NO;
        }
    } else if ([currentViewController isKindOfClass:[RotationViewController class]] || [currentViewController isKindOfClass:[ChimpBlackoutVC class]] || [currentViewController isKindOfClass:[EditPictureVC class]]) {
        return NO;
    }
    return YES;
}



-(UIInterfaceOrientationMask)supportedInterfaceOrientations{
    id currentViewController = self.topViewController;

    UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;


    if ([currentViewController isKindOfClass:[ChimpTabBarController class]]) {
        ChimpTabBarController *tabbarController = (ChimpTabBarController*)currentViewController;

        if (tabbarController.selectedIndex == 0){
            return (UIInterfaceOrientationPortrait | UIInterfaceOrientationPortraitUpsideDown);
        }
    } else if ([currentViewController isKindOfClass:[RotationViewController class]] || [currentViewController isKindOfClass:[ChimpBlackoutVC class]] || [currentViewController isKindOfClass:[EditPictureVC class]]) {
        return (UIInterfaceOrientationPortrait | UIInterfaceOrientationPortraitUpsideDown);
    }
    return UIInterfaceOrientationMaskAll;
}

Is there any way to find out which rotation my device wants to go to, but is not allowed? So that I can change the direction of an arrow, a word etc...

Thanks

Hasya
  • 9,792
  • 4
  • 31
  • 46

1 Answers1

0

I have found a way myself, rather sooner than expected.

For your application you can use :

UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;

But when the rotation is disabled you can always ask the orientation of your device:

[[UIDevice currentDevice] orientation]

Then in your viewcontroller you add an observer for when the device changed orientation:

-->How to check Device Orientation Change From Portrait To Landscape and Vice-Versa in iPad

Hope this will help people in the future.

Community
  • 1
  • 1