4

There is a view controller (let's name it parent), which presents other view controller (let's name it modal) with presentModalViewController:animated:, and then device is rotated. Both controllers support all orientations. Here what's happening:

  1. Right after rotation, modal controller receives didRotateFromInterfaceOrientation:
  2. Just before dismissing modal controller, parent controller receives didRotateFromInterfaceOrientation: too. BUT, it happens only if base SDK is set to 4.3 (or lower). If you set base SDK to 5, parent controller DOES NOT receive this message. With 4.3, I updated parent's interface according to new orientation in didRotateFromInterfaceOrientation:, and it was shown correctly after hiding modal controller, but with iOS 5, it's not called, and parent interface gets messed up after hiding modal controller.

So, what should I do to properly update parent controller's interface to new orientation if device is rotated while modal controller is visible?

1
  • Have the exact same problem. Would be nice to know if anyone has come up with a better solution than the answer above. I don't want my didRotate: code to be called twice.
    – Accatyyc
    Jul 30, 2012 at 9:36

2 Answers 2

1

I've come across a similar problem to this. My solution was to move my orientation handling code into a separate method and call from both the rotation methods and viewWillAppear:

//.h
@interface SomeViewController

- (void)layoutForInterfaceOrientation:(UIInterfaceOrientation)orientation;

@end


//.m
@implementation SomeViewController


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

    UIInterfaceOrientation currentOrientation = [[UIApplication sharedApplication] statusBarOrientation];
    [self layoutForInterfaceOrientation:currentOrientation];
}

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toOrientation duration:(NSTimeInterval)duration {

    [self layoutForInterfaceOrientation:toOrientation];
}

- (void)layoutForInterfaceOrientation:(UIInterfaceOrientation)orientation {

    // layout views
}

@end
3
  • I thought about something like this, but I have many places which use didRotateFromInterfaceOrientation:, and replacing all of them with other methods would take a lot of time and is error-prone. Such behavior in iOS 5 seems like a bug to me, since it doesn't allow us to rely on didRotateFromInterfaceOrientation: being called if orientation changes.
    – breakp01nt
    Jan 21, 2012 at 10:59
  • 1
    You could still do the same thing, but call [self layoutForInterfaceOrientation:[[UIApplication sharedApplication] statusBarOrientation]] from your didRotateFromInterfaceOrientation: methods.
    – Ell Neal
    Jan 21, 2012 at 14:37
  • I use your solution Ell, but it's not the best, because when rotation without showing any modal view, then your parent view execute 2 times that rotation code. Does anyone have a better idea? nyway, thanks a lot Ell.
    – Ricardo
    Jun 8, 2012 at 22:23
0

This might solve the issue. It worked for me:

modal.modalPresentationStyle = UIModalPresentationCurrentContext;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.