plawres
plawres

Reputation: 313

SubView transition resizing after transition

I have a container view controller and child view controllers (Similar to UITabViewController). When transitioning between the view of one child view controller and another child view controller's view, I am using:

let oldView = // get reference to old view
let newView = // get reference to new view
UIView.transition(from: oldView!, to: newView!, duration: 0.3,
                  options: .transitionCrossDissolve, completion: nil)

The issue here, is that the resizing of the newView happens after the transition animation completes, which looks unsightly.

This bad behavior is only happening when the new child view controller is loaded for the very first time. It seems that the viewDidLayoutSubviews method is only called after the transition.

How do I get the newView to be resized BEFORE the transition and not after.

Thanks In Advance.

Upvotes: 5

Views: 496

Answers (1)

Hady Nourallah
Hady Nourallah

Reputation: 442

in your ViewController override func viewWillTransition so it will be something like this

override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
    let oldView = // get reference to old view
let newView = // get reference to new view
UIView.transition(from: oldView!, to: newView!, duration: 0.3,
                  options: .transitionCrossDissolve, completion: nil)

}

Upvotes: 2

Related Questions