1

I have an app developed for iPhone with Xcode which diplays my view controllers in portrait mode with rotation activated.

there's a cell in my table view which triggers a new view controller (iPhoneSignVC) in modal mode, my question is...

is there a way to determine my new modal view controller's orientation from the very begining?? I mean... I want my new view controller to be in landscape mode and without screen rotation feature activated on that particular viewController

so far what I did was to create a new Class which overwrites UINavigation controller's class

#import "UINavigationController.h"
#import "iPhoneSignVC.h"

@implementation UINavigationController (overrides)

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

    if ([currentViewController isKindOfClass:[iPhoneSignVC class]])
        return NO;


    return YES;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    id currentViewController = self.topViewController;

    if ([currentViewController isKindOfClass:[iPhoneSignVC class]]){
        return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
    }

    return (interfaceOrientation == UIInterfaceOrientationMaskAll);
}


@end

I tried this without success...

Thanks in advance for your support folks

Jesús Ayala
  • 2,743
  • 3
  • 32
  • 48

2 Answers2

1

There are multiple considerations that go into this depending on underlying OS. Checkout this very comprehensive question and this solution.

Community
  • 1
  • 1
Nirav Bhatt
  • 6,940
  • 5
  • 45
  • 89
  • 1
    You've posted links to a question which accepted answer is more links. Try to post an answer instead of links as if the links change then the answer is useless – sam_smith Jan 12 '15 at 04:57
1

I guess this is all you need for your modal view to open in the orientation you want:

#import "UINavigationController.h"
#import "iPhoneSignVC.h"


@implementation UINavigationController (overrides)

- (NSUInteger)supportedInterfaceOrientations {

    if ([self.topViewController isKindOfClass:[iPhoneSignVC class]])
        return UIInterfaceOrientationMaskLandscape;

    return UIInterfaceOrientationMaskAll;
}
@end
Jesus
  • 8,456
  • 4
  • 28
  • 40