I have a custom uiView where it has two buttons. I just want to be able to change the height& width of the button when it becomes or leaves focus
override func didUpdateFocus(in context: UIFocusUpdateContext, with coordinator: UIFocusAnimationCoordinator) {
if context.nextFocusedView == noButton{
print("About to be a lot of no in here")
coordinator.addCoordinatedAnimations({
self.yesButton.widthAnchor.constraint(equalToConstant: 360).isActive = true
self.yesButton.heightAnchor.constraint(equalToConstant: 140).isActive = true
self.yesButton.layoutIfNeeded()
}) {
self.noButton.widthAnchor.constraint(equalToConstant: 400).isActive = true
self.noButton.heightAnchor.constraint(equalToConstant: 860).isActive = true
self.noButton.layoutIfNeeded()
}
}
if context.nextFocusedView == yesButton{
coordinator.addCoordinatedAnimations({
self.noButton.widthAnchor.constraint(equalToConstant: 360).isActive = true
self.noButton.heightAnchor.constraint(equalToConstant: 140).isActive = true
self.noButton.layoutIfNeeded()
}) {
self.yesButton.widthAnchor.constraint(equalToConstant: 400).isActive = true
self.yesButton.heightAnchor.constraint(equalToConstant: 160).isActive = true
self.yesButton.layoutIfNeeded()
}
}
}
I just can't figure out why I can't get this to change the button height/width. I know I'm doing something wrong(and pardon if stupid.
You need to call
layoutIfNeeded()
on your buttons after updating their constraints.