UIButton 调整大小动画不是动画

UIButton resize animation is not animating

我正在尝试使用 UIView 动画使我的按钮的大小加倍,但由于某种原因它不起作用,大小正确,但没有动画。

应该为按钮调整大小设置动画的函数

以上代码无关

@objc func createButtonPressed(){
    //Removes the bottom stack with buttons
    if let stackButton = self.view.viewWithTag(50){
        stackButton.removeFromSuperview()
    }
    //Add the button back with half ares size
    bottomHolder.addSubview(rightButton)
    rightButton.setImage(nil, for: .normal)
    rightButton.addTarget(self, action: #selector(anima), for: .touchUpInside)
    rightButton.topAnchor.constraint(equalTo: bottomHolder.topAnchor).isActive = true
    rightButton.trailingAnchor.constraint(equalTo: bottomHolder.trailingAnchor).isActive = true
    rightButton.bottomAnchor.constraint(equalTo: bottomHolder.bottomAnchor).isActive = true




}

@objc func anima(){
    UIView.animate(withDuration: 0.5, delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 1, options: .curveEaseOut, animations: {
        self.rightButton.leadingAnchor.constraint(equalTo: self.bottomHolder.leadingAnchor).isActive = true
        self.rightButton.layoutIfNeeded()
    }, completion: nil)
}

下面是不相关的代码

试试这个:

let buttonFinalWidth = UIScreen.main.bounds.width
DispatchQueue.main.async {
     UIView.animate(withDuration: 5.0) {
           self.rightButton.widthAnchor.constraint(equalToConstant: buttonFinalWidth).isActive = true
           self.view.layoutIfNeeded()
     }
}