iosswiftviewwilltransitiontosize

viewWIllTransition is not getting called in more than one Controller


I am learning to develop iOS application and currently i have 4 view controllers.

In the first viewController i have used the method viewWillTransition to adjust UI at the runtime.

Again in the 4th ViewController i am trying to use the method viewWillTransition, but it is not getting called there.

And when i did comment the method (viewWillTransition) in first controller it magically started to be working in fourth viewController. So i came to the conclusion that viewWillTransition can only be implemented in only one viewController But i need to use it in multiple places.

What is the work around ? How can i fix it ? I am using Swift4 and Xcode9.


Solution

  • Just reposting my comment as an answer,

    You must call super somewhere in the implementation of your viewWillTransition(to: with:). Usually it is the first line.

    It should look something like this:

    super.viewWillTransition(to: size, with: coordinator)
    

    This will allow the superview to pass this method class to all of its subviews. So if you have a UIViewController inside a UITabBarController, calling this method on super will allow all the other tabs to receive this method call.