Reputation: 410
I cannot, for the life of me, figure out why my view won't animate, so I figured maybe it's because of some weird reason that I don't know about. Does anyone have any ideas on less common ways why UIView.animate()
would fail to animate properly? The method I am using to animate my view is:
func animateView() {
print("1")
UIView.animate(withDuration: 5.0, delay: 2.0, options: [], animations: {
self.viewToAnimate.alpha = 0.0
print("2")
}, completion: {_ in
print("3")
})
}
What's even stranger (in my opinion), is that when I run, the console outputs
1
2
3
immediately, and does not take into consideration the delay of 2.0 seconds or the duration of 5.0 seconds... It appears my "animation" is instantaneous, making my view disappear immediately with an alpha of 0.
Any thoughts?
Upvotes: 0
Views: 1455
Reputation: 785
Here are the reasons that I can think of:
1- You can check your device settings General-> Accessibility-> Vision-> Reduce Motion
2- You can check if anywhere in the code you call UIView.setAnimationsEnabled(false)
https://developer.apple.com/documentation/uikit/uiview/1622420-setanimationsenabled
3- Try to call layoutIfNeeded on the view before calling the animation on the view. This has to do with how animations work, it needs initial state and end state and then it projects the difference between both states on a time graph. https://www.objc.io/issues/12-animations/animations-explained/
4- You are not calling the method on the main thread which can make it ask weird. Try to call it in a dispatch_main block
Upvotes: 1