Swift : UIButton 的动画宽度和高度

Swift : Animate width and height of UIButton

在这两个函数中,我想设置按钮收缩(消失)的动画,然后设置它增长(可见)的动画。我能够为它的增长设置动画,但一开始并没有让按钮缩小。关于如何设置按钮收缩动画的任何帮助?

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

    })
}

“1”的比例是当前的大小,如果你想让它变大,这个数字应该大于1。

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

})

}

知道了。所以我必须做的是:

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

})
}

所以最终为了缩小它,我将它设置为 CGAffineTransformMakeScale 的一个非常低的值,例如 (0.1,0.1),然后将 alpha 设置为 0 以产生缩小到无的效果。