Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ios - animate button to shrink in width from the right

Tags:

ios

swift3

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
            }
        })

}
like image 518
user298519 Avatar asked Oct 15 '25 07:10

user298519


1 Answers

It works fine. I have just tested.

enter image description here

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
        })
    }

}

enter image description here

like image 103
Aleksandr Honcharov Avatar answered Oct 16 '25 21:10

Aleksandr Honcharov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!