DidRotateFromInterfaceOrientation: not called for the controller that introduced the modal controller on iOS 5

There is a view controller (let it call it parent) that represents another view controller (let it be called modal) with presentModalViewController:animated: and then the device is rotated. Both controllers support all orientations. Here's what happens:

  • Immediately after rotation, the modal controller receives didRotateFromInterfaceOrientation:
  • Just before disabling the modal controller, the parent controller also received didRotateFromInterfaceOrientation: BUT, this only happens if the base SDK is set to 4.3 (or lower). If you set the base SDK to 5, the parent controller does NOT accept this message. Since 4.3, I updated the parent interface in accordance with the new orientation in didRotateFromInterfaceOrientation: and it was correctly displayed after hiding the modal controller, but with iOS 5 it was not called, and the parent interface got messed up after hiding the modal controller.

So, what should I do to correctly update the interface of the parent controller to a new orientation if the device is rotated while the modal controller is displayed?

+4
source share
2 answers

I ran into a similar problem. My solution was to move my orientation processing code to a separate method and call both 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 
+1
source

This can solve the problem. This worked for me:

 modal.modalPresentationStyle = UIModalPresentationCurrentContext; 
0
source

Source: https://habr.com/ru/post/1390976/


All Articles