ios – Flexible Vertical Spacing in UIScrollView

I have a scrollView that fills the screen and inside there are two stackviews. A top stackview and a bottom stack view. They are each pinned to the top and bottom of the scrollview respectively and I have a vertical spacing constraint between them that can adjust so it is >= 10 (used the solution found here – Fill Vertical Space of UIScrollView). The idea here is that the bottom stackview has some buttons in it and always shows at the bottom.

So this all works and as per the mockup I’m showing below, I can get states 1, 2 and 3 to work (states 2 & 3 allowing for vertical scrolling). The problem I have is trying to get state 4 to work – which is effectively the same as state 1 but with the keyboard visible. When the keyboard is visible, I’m adjusting the scrollView’s contentInsets by the height of the keyboardFrame which all works fine. But because the bottom stack is pinned to the bottom of the scrollView, obvioulsy the scrollview’s contentSize doens’t change nor does the vertical spacing between top and bottom stackview’s adjust.

I’ve been playing around with trying to constrain the views differently but just can’t wrap my head around a simple solution. Any suggestions?

enter image description here