Hello. I am trying to show an image for a short time, in an animated way, and hidden again. This is the function:
@IBOutlet var statusField: UIImageView!
@IBAction func debugbutton(_ sender: UIButton) {
showIcon()
}
override func viewDidLoad() {
super.viewDidLoad()
statusField.isHidden = true
func showIcon() {
statusField.isHidden = false
UIView.animate(withDuration: 1, delay: 0.5, options: UIView.AnimationOptions.transitionFlipFromTop, animations: {
self.statusField.alpha = 0
}, completion: { finished in
self.statusField.isHidden = true
})
}
When I run the function for the first time it works fine but then it stops doing it. The icon is no longer displayed. Any advice on what's going on? Thanks!
In your animation, you set alpha
to 0
, but there's no code to reset it to 1
.
func showIcon() {
statusField.isHidden = false
UIView.animate(withDuration: 1, delay: 0.5, options: UIView.AnimationOptions.transitionFlipFromTop, animations: {
self.statusField.alpha = 0
}, completion: { finished in
self.statusField.isHidden = true
self.statusField.alpha = 1 //<-
})
}
In your shown code, showIcon()
looks like it is nested inside viewDidLoad()
, but it is odd and I assumed it is not nested.