0

Hello I have an app where is the following hierarchy of controllers:

  1. UITabBarCOntroller
  2. Navigation Controller with Table ViewController
  3. UIView controller

The situation is following. I would like to have all the navigation controllers in portrait and only the last controller should be in Landscape. To be correct Landscape Left.

Now the problem is: When I push the new Controller (last one) i want the orientation to be landscape left. I have overrided the methods shouldAutorotate and shouldAutorotateToInterfaceOrientation. I also overrided method supportedInterfaceOrientations with mask LandscapeLeft?

Am I missing something?

I also implement all the rotation methods in the navigation and tabbar controller. in the tabbar :

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // You do not need this method if you are not supporting earlier iOS Versions
    return [self.selectedViewController shouldAutorotateToInterfaceOrientation:interfaceOrientation];
}

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

-(BOOL)shouldAutorotate
{
    return YES;
}

and in the navigation controller :

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

-(BOOL)shouldAutorotate
{
    return YES;
}

Any help will be greatly appreciated.

These are the methods imlemented in the last controller

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}

-(BOOL)shouldAutorotate
{
    return YES;
}

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscapeLeft;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
    return UIInterfaceOrientationLandscapeLeft;
}
Radim Halfar
  • 536
  • 2
  • 6
  • 15

1 Answers1

1

There's one more method you may want to override

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
    return UIInterfaceOrientationLandscapeLeft;
}

The system calls this method when presenting the view controller full screen. You implement this method when your view controller supports two or more orientations but the content appears best in one of those orientations.

Stas
  • 9,925
  • 9
  • 42
  • 77
  • This solutions works great for presenting view controller ! But if I want to push the controller ? to have the logic of the navigation controller ? :-) IS there any similar solution ? :-) – Radim Halfar Apr 08 '13 at 07:52
  • I didn't actually tried it with pushing..is it not working with push? – Stas Apr 08 '13 at 07:53
  • when i Push the controller the method is not called. :/ – Radim Halfar Apr 08 '13 at 07:54
  • Why don't you just return UIInterfaceOrientationLandscapeLeft in this controller for supported orientations? – Stas Apr 08 '13 at 08:06
  • Set the `shouldAutorotate` to NO in that controller – Stas Apr 08 '13 at 08:29
  • Check this answer with tabbar controller http://stackoverflow.com/questions/12662240/how-to-make-app-fully-working-correctly-for-autorotation-in-ios-6 – Stas Apr 08 '13 at 10:05