This code has the problem I encountered
// Fade in and rise up animation
UIView.animate(withDuration: 0.3, animations: {
self.alpha = 1
self.frame.origin.y -= 50
}) { _ in
UIView.animate(withDuration: 0.3, delay: duration, animations: {
self.alpha = 0
self.frame.origin.y += 50 // Moves down
}) { _ in
self.removeFromSuperview()
}
}
This snippet shows the fix
// Fade in and rise up animation
UIView.animate(withDuration: 0.3, animations: {
self.alpha = 1
self.frame.origin.y -= 50
}) { _ in
// This dispatchQueue will allow tap events, it's not acceptable to use the delay parameter from UIView.animate()
DispatchQueue.main.asyncAfter(deadline: .now() + duration) {
UIView.animate(withDuration: 0.3, animations: {
self.alpha = 0
self.frame.origin.y += 50 // Moves down
}) { _ in
self.removeFromSuperview()
}
}
}
Topic:
UI Frameworks
SubTopic:
UIKit
Tags: