0

I have a Navigation Controller that contains a Parent UIViewController that supports all orientation. I want my Parent UIViewController to present its Child UIViewController that only supports Portrait orientation only. How can this be done in iOS 8?

I tried settings the supportedInterfaceOrientations to return UIInterfaceOrientationMaskPortrait only for my Child UIViewController, but it's not working.

iamarnold
  • 229
  • 3
  • 12
  • I belive it bcoz there are some change in iOS 8. I found the answer in this post, check it out. http://stackoverflow.com/questions/26357162/how-to-force-view-controller-orientation-in-ios-8 – vhong Aug 13 '15 at 04:04
  • For more clear explanation, I found his blog following by best practice both Single UIViewController and ViewContoller that embedded with UINavigationConroller and UITabBarController. http://koreyhinton.com/blog/lock-screen-rotation-in-ios8.html – vhong Aug 13 '15 at 04:06

2 Answers2

1

A simple way to do that is:

In your child View Controller you can define this delegate method:

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
    NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationPortrait];
    [[UIDevice currentDevice] setValue:value forKey:@"orientation"];
}

add this line at the begin of your ViewDidLoad method:

NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationPortrait];
[[UIDevice currentDevice] setValue:value forKey:@"orientation"];

This is a simple solution to force orientation in Portrait mode.

melix
  • 468
  • 4
  • 16
0

According to update provided it seems that there is a proper answer at Support landscape for only one view in UINavigationController

Community
  • 1
  • 1
Alex
  • 378
  • 1
  • 14
  • I tried that on the Parent, but the supportedInterfaceOrientations method is not called for the Child's. Any ideas? – iamarnold Apr 15 '15 at 23:03
  • What do you mean with presenting? Presenting modally on top of parent or just pushing into navigation stack? – Alex Apr 15 '15 at 23:32
  • Sry I meant pushing. In my Parient UIViewController, I have a method that pushes my Child UIViewController on my navigationController. I used [self.navigationController pushViewController: childController animated:YES]; for pushing my child UIViewController. – iamarnold Apr 15 '15 at 23:50