UIViewController device rotation delegation methods are not called in iOS5

I am developing an application for the iPhone. In this application, UIViewController (vc1) represents another UIViewController (vc2). vc1 supports both portrait and landscape orientations; vc2 only supports portrait orientation.

  • When vc2 is presented, it requests vc1: shouldAutorotateToInterfaceOrientation: and this returns YES 2.In iOS5 (Beta 7) willRotateToInterfaceOrientation :, didRotateFromInterfaceOrientation: do not receive calls for this sequence. But this works great in iOS4. Is this a bug in iOS5?

Thanks and Regards, Deepa

+6
source share
2 answers

I reported an Apple error and I received the following response:

"Engineering has determined that this problem behaves as expected based on the following information:

The presentation behavior is correct - if in previous versions it differed differently, it was a mistake. Probably an unexpected change in behavior concerns the rejection of VC1, which no longer receives rotation callbacks, but will have a layout in the portrait.

There are other ways to determine what your orientation is when the view controller goes wild. For various reasons, relying on rotation callbacks has proven problematic.

In general, viewController rotation callbacks occur in two cases:

  • Changes in device orientation for view controllers in a window hierarchy
  • Mixed presentation orientation interface. (The lower controller only supports portrait, the device is in the landscape, and a view controller that supports the landscape is presented.) However, this may be an error.

Try using viewWillLayoutSubviews: on iOS 5. "

+8
source

I had a similar problem when testing my application on iOS5. The layout of the subviews in the main view controller, used to mess up if the orientation changes when the view controller is active.

I did to save the flag of the current orientation in the main controller. This flag is updated in two places on the main controller.

  • willAnimateRotationToInterfaceOrientation:
  • viewWillLayoutSubviews (this is only on iOS5)

I write all the logic to set up the subzones by comparing the current orientation with the saved value. If they are different - update the saved orientation, refresh your views.

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { // Any orientation is OK return YES; } - (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { portrait = UIInterfaceOrientationIsPortrait(toInterfaceOrientation); // Code to update subview layout goes here } -(void)viewWillLayoutSubviews { BOOL isPortraitNow = UIInterfaceOrientationIsPortrait(self.interfaceOrientation); if(isPortraitNow != portrait) { DLog(@"Interfaceorientation mismatch!, correcting"); portrait = isPortraitNow; // Code to update subview layout goes here } } 
+4
source

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


All Articles