tvOS按钮是否更新了对Uiview内部焦点的约束?

问题描述 投票:0回答:1

我有一个自定义的uiView,其中有两个按钮。我只想能够在按钮变成焦点或离开焦点时更改按钮的高度和宽度

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.noButton.widthAnchor.constraint(equalToConstant: 360).isActive = true
//              self.noButton.heightAnchor.constraint(equalToConstant: 140).isActive = true
//
         }) {
//              self.yesButton.widthAnchor.constraint(equalToConstant: 360).isActive = true
//              self.yesButton.heightAnchor.constraint(equalToConstant: 140).isActive = true
         }



     }

     if context.nextFocusedView == yesButton{
         coordinator.addCoordinatedAnimations({
             //I think the reverse order no button
         }) {
             //I think reverse order of yes here
         }
     }

 }```

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.
swift tvos tvos13
1个回答
0
投票

更新按钮的约束后,需要在按钮上调用layoutIfNeeded()

© www.soinside.com 2019 - 2024. All rights reserved.