1

My app mainly uses a navigation controller stack, and sometimes displays some controllers modally. In landscape mode the controllers within the nav controller stack work fine, but other view controller shown by presentViewController or previous presentModalViewController always give portrait size view frame (always 768x1024 on iPad iOS 6.0) - even when rotating back and forth between portrait and landscape.

Kind of related to A view controller is in landscape mode, but I'm getting the frame from portrait mode? however the checked answer is not helping. If I add the later view controller as part of the navigation stack the resize happening on first load and subsequent rotations work. The problem appears only, as stated above, when adding the controller by presentViewController.

Community
  • 1
  • 1
Jonny
  • 15,955
  • 18
  • 111
  • 232

1 Answers1

3

wrap the modal branches to another nav controller and define the rotation mask there. in iOS6 the - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) works only on nav stack branches and entire branch should work the same way.

So, subclass the nav:

@interface CLNotRotatingNavController : UINavigationController

and in its .m add this

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return NO;
}

- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskLandscape;
}

- (BOOL) automaticallyForwardAppearanceAndRotationMethodsToChildViewControllers {
    return YES;
}

and wrap all the modal branches to this nav. This will lock everything to lanscape where necessary.

whiteagle
  • 1,158
  • 10
  • 12
  • Great. It works. I added the modal controller (I only have one) as root controller of CLNotRotatingNavController (which I actually allow to rotate for iPad, but only portrait for iPhone as I have a universal app) and display it with presentViewController. Dismiss with dismissViewControllerAnimated. Nice workaround. But makes you wonder if we do something wrong from the beginning or if this is a bug (feature) of iOS? I remember filing a bug about a similar bug two years before - A year later Apple responded that they fixed the bug. :-P – Jonny Oct 28 '12 at 16:09
  • they call it feature, it is not a bug because they did it on purpose (even documented), but I can't find any reason to justify that move. It took me two days to figure it out. :/ – whiteagle Oct 28 '12 at 16:12
  • @whiteagle:This shows error please give some code to display model viewcontroller in customNavigation controller – TamilKing Nov 21 '13 at 06:20
  • I dont know why Apple decided to change that behavior. I can't figure out any logical reason for breaking this functionality. – LightningStryk Aug 04 '14 at 15:02