User1238 User1238 - 2 months ago 38
Swift Question

ViewWillTransitionToSize don't works if used in two classes

I want to detect the orientation change in different ViewControllers. I used this code

override func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) {
print("roration detected- ViewController 1")
}


It worked fine until I added this code in another ViewController. Now the function is executed only in the second ViewController. If I deleted from there than it start working in the first ViewController again. Do you have an idea what the problem is?

Answer

You should try to call super method:

override func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) {
    super.viewWillTransitionToSize(size, withTransitionCoordinator: coordinator)
    print("rotation detected- ViewController 1")
}