2

I have following Controllers, (I have selected all types orientation modes in iPad)

Here is my iPad Storyboard layout

Custom NavigationController > Loading Ctrl > Main Controller.

My Custom Navigation Contains

-(BOOL)shouldAutorotate
{
    return [[self.viewControllers lastObject] shouldAutorotate];
}

-(NSUInteger)supportedInterfaceOrientations
{
    return [[self.viewControllers lastObject] supportedInterfaceOrientations];
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
}

In my Loading Controller

-(BOOL)shouldAutorotate
{
    return YES;
}

-(NSUInteger)supportedInterfaceOrientations
{
    if (UIUserInterfaceIdiomPad == UI_USER_INTERFACE_IDIOM())
        return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
    else
        return UIInterfaceOrientationMaskPortrait;
}

The supportedInterfaceOrientations gets called as usual and everything seems ok, But when I push my Main Controller using performSegue

-(NSUInteger)supportedInterfaceOrientations
{
    if (UIUserInterfaceIdiomPad == UI_USER_INTERFACE_IDIOM())
        return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
    else
        return UIInterfaceOrientationMaskPortrait;
} 

No more calls in MainController. Why is that?

Muhammad Umar
  • 11,391
  • 21
  • 91
  • 193

2 Answers2

3

There is one trick.

Fetch the status bar from the Application and rotate it.

[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:YES];

Create and display and dismiss an empty view controller modally.

UIViewController *mVC = [[UIViewController alloc] init];
[self presentModalViewController:mVC animated:NO];
[self dismissModalViewControllerAnimated:NO];

Now your device shoud have been forced to rotate. You could now segue to a proper view controller or push one using the navigation controller.

Hermann Klecker
  • 14,039
  • 5
  • 48
  • 71
  • This worked, however, it useses deprecated functions (present and dismiss) – Jeef Feb 17 '14 at 16:17
  • Yes, they were depricated with iOS 6 and replaced by ´presentViewController:animated:completion:´ and ´dismissViewControllerAnimated:completion:´ . I did not yet try whether they work alike. If you give it a try I'd appreciate your feedback. – Hermann Klecker Feb 17 '14 at 17:51
  • It "sort of worked" meaning it didn't work in every case. Still trying to tease the why out of my application however... – Jeef Feb 17 '14 at 18:11
1
- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
return (interfaceOrientation == UIInterfaceOrientationPortrait);//choose portrait or landscape
}
- (BOOL) shouldAutorotate{
return NO;
}
- (NSUInteger) supportedInterfaceOrientations{
return UIInterfaceOrientationMaskPortrait;//choose portrait or landscape, same as above
}
n00bProgrammer
  • 4,261
  • 3
  • 32
  • 60