I am working with an animation. What I would like to happen is for the UIButton to be removed when the animation is completed, but it always disappears before the animation is completed. Am I missing something?
func buttonPressed(sender: UIButton!){
UIView.animateWithDuration(1.0, delay: 0.5, options:[] , animations: {
background.backgroundColor = Yellow
}, completion: {finished in button.removeFromSuperview()})
}
Try this:
func buttonPressed(sender: UIButton!){
UIView.animateWithDuration(1.0, delay: 0.5, options:[] , animations: {
background.backgroundColor = Yellow
}, completion: {finished in
if finished {
button.removeFromSuperview()
}
})
}
Use the finished
flag in the completion block to remove your button
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.