tvOS 按钮更新对 Uiview 中焦点的限制?



我有一个自定义的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.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()
}
}
}

我只是想不通为什么我不能让它来更改按钮的高度/宽度。我知道我做错了什么(如果愚蠢,请原谅。

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

相关内容

  • 没有找到相关文章

最新更新