I have a tool pane which in compact H mode, will be at the bottom spanning the full screen, but in compact V mode (or non compact H mode), it will be on the right as a floating pane. How do I get the target UITraitCollection + the target size? They seem to be in 2 different methods:
override func willTransition(to newCollection: UITraitCollection, with coordinator: UIViewControllerTransitionCoordinator) {
// need size rect
}
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
super.viewWillTransition(to: size, with: coordinator)
// need traits
}
I need both infos for animating things properly! Thanks so much!
You can in fact get both values, the size and the trait collection in both methods, by operating on the
UIViewControllerTransitionCoordinator.Apple's idea here is to simplify the call site with one context parameter that can be queried for multiple properties, and also execute asynchronously so that the values for the final transitioned view or VC can be fetched accurately in one place even before the update occurs.
While you can perform animations in either of the
WillTransitionmethods, I would use thecoordinator.animate(alongsideTransition:completion:)method if possible rather thancoordinator.notifyWhenInteractionChanges(_:)since it synchronizes the system animation alongside your own custom animation and you can still query thecontextfor the newtraitCollectionorframe.sizeusing the techniques above.