动画和从SuperView中删除UIButton

时间:2016-02-18 23:37:44

标签: ios swift

我正在制作动画。我想要发生的是在动画完成时移除UIButton,但它在动画完成之前总是消失。我错过了什么吗?

func buttonPressed(sender: UIButton!){

    UIView.animateWithDuration(1.0, delay: 0.5, options:[] , animations: {
        background.backgroundColor = Yellow
        }, completion: {finished in button.removeFromSuperview()})
}

1 个答案:

答案 0 :(得分:0)

试试这个:

func buttonPressed(sender: UIButton!){

    UIView.animateWithDuration(1.0, delay: 0.5, options:[] , animations: {
        background.backgroundColor = Yellow
        }, completion: {finished in 
            if finished {
                button.removeFromSuperview()
            }
        })
}

使用完成块中的finished标志删除按钮