The book has us hard code the edge insets for the list view controller:
segue.destination.additionalSafeAreaInsets = UIEdgeInsets(top: 0, left: 0, bottom: 160, right: 0)
However, this seems brittle to me. If the size of the button or stackview ever change, we have to remember to update this value, and use trial and error to get it to be the right size.
It seems like a better approach would be to calculate the bottom inset value based on the height of the button and stack view (and the spacing between them). I tried to do that using code like this:
//calculate the bottom inset value let bottom = stackView.bounds.height + addMoodButton.bounds.height + 20 // and now use it to set the bottom safe area insets segue.destination.additionalSafeAreaInsets = UIEdgeInsets(top: 0, left: 0, bottom: bottom, right: 0)
But this doesn’t work. The calculated value is not big enough for the content to properly scroll out from under the button. I presume this is because one of the items (bounds or insets) is using raw pixels, whereas the other is using points. But I’m not sure which. This leads me to 2 questions:
- Simply, what is the best way to calculate the bottom insets value instead of hard coding the value.
- Teach me to fish … how could I have figured that out from the developer documentation? I looked up the docs for several objects that are used here (
UIEdgeInsets), and none of them give any indication if the values they use are points or pixels. How does a developer find these kinds of things out? I find the documentation to be significantly lacking in these areas.