Question

I have multi storyboard in my app and i want to keep a storyboard orientation to portrait. Is it is possible ?? If yes how??

Thanks in advance.

Was it helpful?

Solution

What you want can be done... (below is example for only landscape orientation for app)

Create custom navigation controller

CustomNavigationController.h

#import <UIKit/UIKit.h>

@interface CustomNavigationController : UINavigationController

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation;
-(BOOL)shouldAutorotate;
- (NSUInteger)supportedInterfaceOrientations;

@end

CustomNavigationController.m

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


- (NSUInteger)supportedInterfaceOrientations
{
    if (![[self.viewControllers lastObject] isKindOfClass:NSClassFromString(@"ViewController")])
    {
        return UIInterfaceOrientationMaskLandscape;
    }
    else
    {
        return [self.topViewController supportedInterfaceOrientations];
    }
}

Include below in all files where you want only landscape...

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    NSLog(@"1. shouldAutorotateToInterfaceOrientation");
    if (interfaceOrientation==UIInterfaceOrientationMaskPortrait) {
        return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
    }

    return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft)
    ||(interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationLandscapeLeft;
}

- (BOOL)shouldAutorotate
{
    return YES;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top