I'm using
UIView.animated(withDuration:animations:completion:)
function and there are sometimes that there is no animations affected in the animations block
For example:
Let's assume that I have a view
, and it's frame.origin.y
is already equals to 0.
Now the animation that I wan't to make is that:
UIView.animate(
withDuration: 1,
animations: {
self.view.frame.origin.y = 0
}
completion: { completed in
guard completed else { return }
// do something
}
)
The completion block called after 1 second instead of instantly.
How can I make that the completion block will called instantly if there are no animations affected in the animations block without any duration.
origin.y
was already0
doesn't mean there wouldn't be an animation. You need to check for this case yourself and just not animate. – Arkku