Rotation and containment api

I have two view controllers, A and B. A is designed to support only Portrait, while B can support landscape. I show B using containment api.

[self addChildViewController:child]; [self.view addSubview:child.view]; child.view.frame = self.view.bounds; [child didMoveToParentViewController:self]; 

I implemented

  - (BOOL)shouldAutorotate { UIViewController *current = _presentingChild ? _child : self; return [current shouldAutorotate]; } - (NSUInteger)supportedInterfaceOrientations { UIViewController *current = _presentingChild ? _child : self; return [current supportedInterfaceOrientations]; } 

everything works like a charm. If the devices are landscape and A and I represent B, the rotation immediately turns.

the problem occurs when I fire B. If the device has landscape A, the landscape is displayed (and this should not be).

Do you have any suggestion on how to deal with this problem? I know that I can use a modal controller, and this will solve the problem. But I do not want to use modal vc for this particular situation.

+4
source share
1 answer

If I understand correctly, the shouldAutorotate and supportedInterfaceOrientations methods are inside A viewcontroller, which contains B viewcontroller.

If I am right, the way you implemented these two methods is bad: when the current view controller is self (if the _presentingChild condition is false), you must have infinite recursion, because, for example, shouldAutorotate will be called recursively without end (you return [self shouldAutorotate] ).

So, if you are not experiencing infinite recursion, there are only two possibilities:

  • two methods are never called
  • _presentingChild condition is always true

Check and let me know

+1
source

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


All Articles