Dmytrii G.
Dmytrii G.

Reputation: 547

What the effect after interface transition?

In my project there are VC and other VC as container. I try to use viewWillTransitionToSize method, but after transition Interface of child VC(which is in container) isn't enable to use by touch.

I have no idea what that is the effect or problem. Have anyone any idea about my situation?

Thanks for all answers!

Upvotes: 1

Views: 42

Answers (1)

Dmytrii G.
Dmytrii G.

Reputation: 547

I found solving this problem. If you have same problem, check your viewWillTransitionToSize override func. All actions with sizes, views, colors, location should be done along transition. Like this:

Swift 4.1

...
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
    super.viewWillTransition(to: size, with: coordinator)
    coordinator.animate(alongsideTransition: { (_) in
        // there will be your handler for UI elements.
    }, completion: { (_) in 

    })
}
...

In my project I have UIPageVC, which exists pages (VCs). I handle transition in PageVC func for each page, besides page(VC), which is in view in the transition moment. And all works. This is example of my code:

MainPageViewController class:

...
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
    super.viewWillTransition(to: size, with: coordinator)
    coordinator.animate(alongsideTransition: { (_) in
        // handlers for my PageVC

        for vc in self.orderedViewControllers {
            if vc != self.orderedViewControllers[self.currentPageIndex{
                vc.viewWillTransition(to: size, with: coordinator)
            }
        }

    }) { (_) in
        print("\nDONE: PAGEVC Rotated.")
    }
}

Maybe this code will help anyone in future.

Upvotes: 0

Related Questions