Reputation: 281
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.
Upvotes: 1
Views: 2523
Reputation: 367
Also -- If using a custom containerViewController with child viewControllers?
If you have added a child viewController's view to a parent viewController as a subview you must call the .addChild(_:)
method on the parent viewController to create the parent-child relationship between the two view controllers.
Upvotes: 0
Reputation: 639
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.
Upvotes: 5