iosswiftcgaffinetransformscale

Scale UIButton Animation- Swift


I'm trying to do scale animation for UIButton when its clicked but what I'm trying to accomplish is when the button clicked I need the UIButton to be smaller to the inside then it comes back to its same size (like a bubble).

I tried the following:

button.transform = CGAffineTransformMakeScale(-1, 1)

UIView.animateWithDuration(0.5, animations: { () -> Void in

    button.transform = CGAffineTransformMakeScale(1,1)

})

Solution

  • Try this

    UIView.animate(withDuration: 0.6,
        animations: {
            self.button.transform = CGAffineTransform(scaleX: 0.6, y: 0.6)
        },
        completion: { _ in
            UIView.animate(withDuration: 0.6) {
                self.button.transform = CGAffineTransform.identity
            }
        })