I have the following screen, in order to centre the boxes between the uilabel and the keyboard I created a simple calculation where I added the header height then the uilabel height and then the keyboard height minus the whole screen size and divided everything by two in order to get the centre point [i added the code below although it's not relevant]
The issue is that in order to get the UILabels height I have to set the constraints in viewDidLayoutSubviews(). Now the idea is that every time you fill one box the next box becomes the first responder but that doesn't work because every time a box becomes a first responder viewDidLayoutSubviews() is being called.
What can I do about this ? is there a way to get the height of uiLabel without calling viewDidLayoutSubviews().
This is the code for centering the boxes :
override func viewDidLayoutSubviews() {
let allItems = headerC.frame.height + stackViewOfDefin.frame.height + 270 + 20
let getSpace = UIScreen.main.bounds.height - allItems
let stackview = UIStackView(arrangedSubviews: gameBoxes)
stackview.axis = .horizontal
stackview.spacing = 5
stackview.distribution = .fillEqually
stackview.translatesAutoresizingMaskIntoConstraints = false
self.view.addSubview(stackview)
NSLayoutConstraint.activate([
stackview.topAnchor.constraint(equalTo: secondLine.bottomAnchor, constant: getSpace/2-30),
stackview.centerXAnchor.constraint(equalTo: self.view.centerXAnchor),
stackview.leadingAnchor.constraint(greaterThanOrEqualTo: view.leadingAnchor, constant: 10),
stackview.trailingAnchor.constraint(lessThanOrEqualTo: view.trailingAnchor, constant: -10)
])
}