I am using CGAffineTransform to shrink a button on click. The button shrinks in width but from the left and right meeting in the middle. However, I want the button to shrink from the right. A weird analogy is like the button is a piece of paper, and I lit the right side with a match and it burns the paper, destroying it towards the left. How would I achieve such functionality?
func animateStartButtonExit() {
UIView.animate(withDuration: 0.5,
animations: {
self.startButtonOutlet.transform = CGAffineTransform(scaleX: 0.1, y: 1)
},
completion: { _ in
UIView.animate(withDuration: 0.5) {
self.startButtonOutlet.isHidden = true
self.startButtonOutlet.transform = CGAffineTransform.identity
}
})
}
It works fine. I have just tested.
class ViewController: UIViewController {
@IBOutlet weak var button: UIButton!
@IBOutlet weak var widthConstraint: NSLayoutConstraint!
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func click(_ sender: UIButton) {
widthConstraint.constant = 10
UIView.animate(withDuration: 5, animations: {
self.view.layoutIfNeeded()
}, completion: { _ in
self.button.isHidden = true
// For example, back to the normal width
self.widthConstraint.constant = 168
})
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With