0

I tried setting shouldAutorotate to false supportedInterfaceOrientations to UIInterfaceOrientationLandscapeRight

-(BOOL)shouldAutorotate{
    return NO;
}

-(NSUInteger)supportedInterfaceOrientations{
    return UIInterfaceOrientationLandscapeRight;
}
halfer
  • 19,824
  • 17
  • 99
  • 186
Mahendran Candy
  • 1,114
  • 17
  • 17

1 Answers1

3

supportedInterfaceOrientations is enough, just remove shouldAutorotate. or you can do so.

NavigationController.m

@interface NavigationController : UINavigationController

@end

@implementation NavigationController

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

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {
    [super pushViewController:viewController animated:animated];
    [self refreshOrientation];
}

- (UIViewController *)popViewControllerAnimated:(BOOL)animated {
    id vc = [super popViewControllerAnimated:animated];
    [self refreshOrientation];
    return vc;
}

- (NSArray<UIViewController *> *)popToViewController:(UIViewController *)viewController animated:(BOOL)animated {
    id vcs = [super popToViewController:viewController animated:animated];
    [self refreshOrientation];
    return vcs;
}

- (NSArray<UIViewController *> *)popToRootViewControllerAnimated:(BOOL)animated {
    id vcs = [super popToRootViewControllerAnimated:animated];
    [self refreshOrientation];
    return vcs;
}

- (void)refreshOrientation {
    UIViewController *vc = [UIViewController new];
    [UIViewController attemptRotationToDeviceOrientation];
    [self presentViewController:vc animated:NO completion:nil];
    [vc dismissViewControllerAnimated:NO completion:nil];
}
@end

in ViewController implement this method

-(UIInterfaceOrientationMask)supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskLandscapeLeft;
}
  • Its still not working When the app is in portrait mode and when its pushed to the view controller still its in portrait mode.I want that particular view controller to be locked in landscape mode even when the device is in portrait or landscape. – Mahendran Candy Jan 11 '17 at 04:49
  • Methods that change orientation are now deprecated and depends on iOS version, I would suggest to add a view and perform transformation. Also there is a [workaround](http://stackoverflow.com/questions/26357162/how-to-force-view-controller-orientation-in-ios-8) but it's a hack and I wouldn't suggest to do. – Gor Baghdasaryan Jan 11 '17 at 08:01