0

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.

Havic
  • 99
  • 1
  • 6

1 Answers1

0

You need to call layoutIfNeeded() on your buttons after updating their constraints.

Daniel Storm
  • 18,301
  • 9
  • 84
  • 152
  • I updated my code to reflect your answer but still does not work. I'm doing something incorrect. – Havic Nov 22 '19 at 23:47