How to allow rotation of only one view in the navigation stack?

I have ViewControllers A and B in the navigation stack. A does not support landscape orientation, B does. If the user rotates horizontally while viewing B and then presses the back button, now A is in the landscape. How can I prevent this? Is there a good reason why the toAutorotateToInterfaceOrientation method for A is not respected?

+4
source share
2 answers

This is really very annoying for view controllers. And it seems that this is not a problem for autorotation. Perhaps it would be better to return NO from B shouldAutorotateToInterfaceOrientation, and then manually rotate the image. Then it does not affect A.

+2
source

yes, I hate it too ... all I decided to solve was to do it myself:

- (void)myAutomaticRotation{ if (A.view.frame.size.width > A.view.frame.size.height) { [UIView beginAnimations:@"View Flip" context:nil]; [UIView setAnimationDuration: 0.5f]; [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; self.view.transform = CGAffineTransformIdentity; self.view.transform = CGAffineTransformMakeRotation(M_PI/2); self.view.bounds = CGRectMake(0.0f, 0.0f, 320.0f, 480.0f); A.view.frame = CGRectMake(0,0,320, 480); [UIView commitAnimations]; } } 

you can call myAutomaticRotation in the main / super UIViewController when you go to A.view, and in the same place you should use:

 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { } 

where you can check the used view (A, B) and enable landscape mode only for B ...

Luca

+1
source

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


All Articles