I've implemented a custom transition from ViewController A (which is embedded in a UINavigationController) to ViewController B.
The transition "slides" VC B from the bottom until it takes 1/2 the vertical screen size - using a custom UIViewControllerAnimatedTransitioning
object. The custom presentation also shifts the presenting VC A so it slides up with the incoming VC B using animateAlongsideTransition(in:animation:compeltion)
called in presentationWillBegin()
override of the custom UIPresentationContorller
. Think split screen with lower 1/2 of the presenting VC on top and the presented VC on the bottom.
Everything is working as expected except for one nagging case that I cannot seem to solve:
- VC A has some sub-views (buttons) which are constrained (auto-layout in interface builder) to the top layout guide of VC A (again, VC A is in a NavC).
- When I present the modal view (B), these subviews are pushed up as part of the transition (great) and down again when VC B is dismissed (great).
- But while VC B is presented, and the app is put into the background and then back to the foreground, VC A's subviews are displayed at top the screen - i.e in the middle of VC A's view instead of the top (bad). When VC B is dismissed they stay stuck in the middle (bad) - only initiating a full VC "redraw" by navigating out of VC A and back fixes the problem.
I understand that the problem somehow lies with the top layout guide being recalibrated when coming back to the foreground but can't figure out how to fix it before the views are displayed.
One way to go is to set the constraints of the sub-views to "superview top" instead of "top layout guide" but then that beats the point of auto layout as part of a NavC.
- VC A's
viewWillAppear/viewWillDisappear
are never called in this case (as VC A's view is never totally dismissed). containerViewWillLayoutSubviews/containerViewDidLayoutSubviews
of the customUIPresentationController
not called either in this case
Any ideas greatly appreciated.
iOS 10, Xcode 8.3
Compiling with Xcode 9 and running on iOS 11 seems to have solved this. Referring to my description above, in Xcode 9/iOS 11:
When VC B is dismissed the buttons of VC A are repositioned automatically at the top of VC A. The repositioning isn't animated and looks weird but its working as expected and honouring the auto-layout constraint to the top layout guide.