-1

I want to support the autorotation in iOS 6 and 7. In my project I have a UITabBar with 4 ViewControllers. Only one ViewController of them should support the autorotaion to Portrait and Landscape. The other views should support only the Portrait style.

I hope you have an idea how to implement this function. shouldautorotatetointerfaceorientation doesn't work in iOS 7 :(

I added a UITabBarConntroller to control the autorotation

- (BOOL)shouldAutorotate {
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations {
    if (self.selectedIndex == 1) 
        return (UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationPortrait);
    else 
        return UIInterfaceOrientationMaskPortrait;
}

Maybe there is a way to change the Orientation manual when the View with the index 1 did disappear??

I hope you have a solution!

Andy Obusek
  • 12,614
  • 4
  • 41
  • 62
Maxim
  • 317
  • 1
  • 5
  • 13
  • 1
    You could define those methods in each view controller, and again place `return self.selectedViewController.shouldAutorotate;` and `self.selectedViewController.supportedInterfaceOrientations;` in the Tab Bar Controller class. This will retrieve the `shouldAutorotate` and `supportedInterfaceOrientations` values from the active view controller and use them for the tab bar controller. – sooper Apr 17 '14 at 16:02

2 Answers2

0
  • Open project

  • Go to the General tab

  • Under orientation options check all checkbox orientation that you need to support

Go to the implementation of first view controller and add this code:

- (BOOL)shouldAutorotate
{
    return YES;
}

Also for supporting iOS 6 implement method:

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

Go to all other view controllers that are represented your tabs and set:

- (BOOL)shouldAutorotate
{
    return NO;
}

Also for supporting iOS 6 implement method:

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

Check this link as well

Matrosov Oleksandr
  • 25,505
  • 44
  • 151
  • 277
0

Set the orientations settings like this: enter image description here

In UITabBarController:

-(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
{
    if (self.selectedViewController) 
        return [self.selectedViewController supportedInterfaceOrientations];

    return UIInterfaceOrientationMaskPortrait;
}

-(BOOL)shouldAutorotate
{
    return YES;
}
nithin
  • 2,457
  • 1
  • 30
  • 50
  • This will not work, it will still be possible to open a view controller in an unsupported orientation. – Léo Natan Apr 17 '14 at 16:19
  • Is there a way to set one view to Landscape and the other views to portrait without autorotation? – Maxim Apr 17 '14 at 16:36