4

my project have UITabbar, UınavigationBar and UIViewContoller.

-UITabbar
 —UINavigationController
   —UIViewController

Question: how can i do landscape disable just one viewController? i want to only portrait view but for just one view.

Erkam KUCET
  • 485
  • 8
  • 21
  • 1
    possible duplicate of [disable autorotate on a single UIViewController in iOS6](http://stackoverflow.com/questions/17370806/disable-autorotate-on-a-single-uiviewcontroller-in-ios6) – JustSid Nov 09 '14 at 21:14
  • yes.Succesed. Other solution: http://stackoverflow.com/a/14738180/3215402 – Erkam KUCET Nov 09 '14 at 21:17

1 Answers1

4

disable autorotate on a single UIViewController in iOS6

Add this to your app delegate

- (NSUInteger) application:(UIApplication *)application     supportedInterfaceOrientationsForWindow:(UIWindow *)window {

if ([[window.rootViewController presentedViewController] isKindOfClass:[YourViewController class]])
    return UIInterfaceOrientationMaskPortrait;
else
    return UIInterfaceOrientationMaskAllButUpsideDown;
}

EDIT 2

I recently found out about this, and it has been working perfectly for me. Add this code to your view controller

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}

And in your viewWillAppear add

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];

    ///Disable orientation changes
    NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationPortrait];
    [[UIDevice currentDevice] setValue:value forKey:@"orientation"];
}
Community
  • 1
  • 1
MendyK
  • 1,643
  • 1
  • 17
  • 30
  • Partially Working. If I move back from Landscape ViewController to Portrait ViewController. It was not giving desired result. Please give feedback if you have any solution for that – Leo Moon85 Sep 01 '15 at 10:01
  • @LeoMoon85 Answer updated. Let me know if it helps you. – MendyK Sep 02 '15 at 02:24
  • I also add one more thing...in viewDidAppear, [UIView setAnimationsEnabled:NO]; and again [UIView setAnimationsEnabled:YES]; in viewWillAppear. It helps viewing better when moving back from landscape to portrait and vise versa. Thx. – Leo Moon85 Sep 02 '15 at 11:03