OriginalAlchemist
OriginalAlchemist

Reputation: 411

Swift : Animate width and height of UIButton

Inside of these two functions, I want to animate the button shrinking(gone), then animate it growing(seen). I was able to animate it growing, but not at first have the button shrink. Any help on how to animate a button shrinking?

func progressBarButtonFadeOut(){
    UIView.animateWithDuration(0.2, animations: {
    //timeCapDesign is a UIButton
        self.timeCapDesign.transform = CGAffineTransformMakeScale(0, 0)

    })
}

//Progress Bar Fade In Buttons
func progressBarButtonFadeIn(){
    UIView.animateWithDuration(0.2, animations: {

        self.timeCapDesign.transform = CGAffineTransformIdentity

    })
}

Upvotes: 0

Views: 3586

Answers (2)

OriginalAlchemist
OriginalAlchemist

Reputation: 411

got it. So what i had to do was this:

func progressBarButtonFadeOut(){
UIView.animateWithDuration(0.2, animations: {
//timeCapDesign is a UIButton

    self.timeCapDesign.alpha = 0

    self.timeCapDesign.transform = CGAffineTransformMakeScale(0.1, 0.1)

})
}

//Progress Bar Fade In Buttons
func progressBarButtonFadeIn(){
UIView.animateWithDuration(0.2, animations: {

    self.timeCapDesign.alpha = 1

    self.timeCapDesign.transform = CGAffineTransformIdentity

})
}

So ultimately to shrink it i set it to a value of the CGAffineTransformMakeScale really low such as (0.1,0.1) and then animated the alpha to 0 to give the effect that its shrinking to nothing.

Upvotes: 3

Aline Kolczycki Borges
Aline Kolczycki Borges

Reputation: 172

The scale of "1" is the current size, and if you want to animate it growing, the number should be bigger than 1.

func progressBarButtonFadeOut(){
UIView.animateWithDuration(0.2, animations: {
//timeCapDesign is a UIButton
    self.timeCapDesign.transform = CGAffineTransformMakeScale(1.5, 1.5)

})

}

Upvotes: 0

Related Questions