Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 483
plawres Avatar asked Oct 30 '22 07:10

plawres


1 Answers

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)

}
like image 159
Hady Nourallah Avatar answered Nov 15 '22 05:11

Hady Nourallah