I've been trying to vertically centre a UILabel across all devices, both when the keyboard isn't visible and when it is visible.
I previously tried to adjust the top constraint by doing this: self.emptyStateMessageTopConstraint.constant = (self.view.frame.size.height / 2 ) - (self.emptyStateMessageHeight.constant / 2 )
This should have given me the mid point when the keyboard wasn't visible.
I did this when the keyboard was visible:
self.emptyStateMessageTopConstraint.constant = (self.view.frame.size.height - keyboardHeight) / 2 - self.emptyStateMessageHeight.constant / 2
In theory, it should have worked but it wasn't entirely vertically centre.
As you can see below, it's not centred.
I scrapped that idea and tried to centre vertically. It worked perfectly across all devices when the keyboard is not visible as seen below.
Now my issue is, how can I programmatically change the vertical constant when the keyboard is visible across all devices.
I'm struggling since the calculation I used previously can't really be used to change the vertical constant.