繁体   English   中英

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

    })
}

得到它了。 所以我要做的是:

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,以使其缩小为零。

比例“ 1”是当前尺寸,如果要对其进行动画处理,则该数字应大于1。

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

})

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM