User Interaction during Animation

Manish Singh
Dec 29, 2020

--

In iOS, the simples way to achieve Animation in a UIView is through `UIView.animate` block.

I was using this block recently and stumbled upon one issue, where I was not able to interact with the view while the animation was running. I figured it out easily, though.

UIView.animate(withDuration: 1.0, delay: 0.0, options:[.repeat, .allowUserInteraction, .autoreverse], animations: {

self.selectedView.backgroundColor = UIColor(red: red, green: green, blue: blue, alpha: alpha)

}, completion:nil)

In above code, `allowUserInteraction` options makes this happen. So, next time, if you are stuck with something similar just make sure to add that property in the options array.

A Gif from my personal project shows how an animated cell becomes tappable after adding `allowUserInteraction`.

--

--

No responses yet