UIViewController inside the root ViewController does not rotate

I have a UIViewController that I want to add on top of the entire application as an independent layer. So I tried to add it to UIWindow using [self.window addSubview: viewController.view] in the application delegate.

However, when the user rotates the device, I do not get the willRotateToInterfaceOrientation event in my view controller. So I tried to do what was suggested here : I added a view controller as a sub-task of the window root view controller in the applicationโ€™s split, but my willRotateToInterfaceOrientation is still not being called.

What should I do?

+4
source share
2 answers

Your rootViewController acts as a container view controller.

In iOS 5.0 and later, custom subclasses of the UIViewController can now act as container view controllers. The UINavigationController and UITabBarController classes are examples of container view controllers provided by UIKit. The idea of โ€‹โ€‹a container controller is that it controls the presentation of content from its contained view controllers, also known as its child view controllers. Child content can be presented as is or in combination with other other user views controlled by the container view controller.

What you do is implement your own hierarchy of views, so you are responsible for passing UILifecycle-Events through this hierarchy. iOS> = 5.0 supports the creation of such a container viewControllers, offering

- (void)addChildViewController:(UIViewController *)childController - (BOOL)automaticallyForwardAppearanceAndRotationMethodsToChildViewControllers 

(and much more). For iOS <5.0, you unfortunately have to do this manually.

+7
source

In your root controller, you must link to your independent Layer controller and redirect the willRotateToInterfaceOrientation command.

Your rootViewController will receive messages, and you can invoke the willRotateToInterfaceOrientation command on an independent controller.

+2
source

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


All Articles