Вот код для анимации и преобразования кнопки. Он отлично работает, как вы аспект
func changeButtons(selectedButton:UIButton)
{
firstBtn.backgroundColor = .white
firstBtn.setTitleColor(.black, for: .normal)
animateButton(button: firstBtn, transformBy: .identity)
secondBtn.backgroundColor = .white
secondBtn.setTitleColor(.black, for: .normal)
animateButton(button: secondBtn, transformBy: .identity)
thirdBtn.backgroundColor = .white
thirdBtn.setTitleColor(.black, for: .normal)
animateButton(button: thirdBtn, transformBy: .identity)
selectedButton.backgroundColor = .black
selectedButton.setTitleColor(.white, for: .normal)
animateButton(button: selectedButton, transformBy: CGAffineTransform(scaleX: 1.2, y: 1.2))
}
func animateButton(button : UIButton,transformBy:CGAffineTransform)
{
UIView.animate(withDuration: 0.2) {
button.transform = transformBy
self.view.layoutIfNeeded()
}
}
@IBAction func btnFirstPress(_ sender: UIButton)
{
changeButtons(selectedButton: firstBtn)
}
@IBAction func btnSecondPress(_ sender: UIButton)
{
changeButtons(selectedButton: secondBtn)
}
@IBAction func btnThirdPress(_ sender: UIButton)
{
changeButtons(selectedButton: thirdBtn)
}