iosswiftuibuttonanimatewithduration

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

    })
}

Solution

  • 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.