Categories
Programming

Animation fun with UIView.AnimateAsync()

Xamarin.iOS 6.4 brought async/await support to iOS devices. Apart from supporting the idiom with the Mono 3.0 compiler, Xamarin also invested into adding awaitable versions of all long-running calls in Apple’s iOS API. One of my favorites is

UIView.AnimateAsync()

taking an Action or lambda to animate asynchronously without blocking the UI thread.

The fun begins when you use this to chain animations. Here’s an example of doing a horizontal shake animation that could be used to indicate an invalid entry:

3 replies on “Animation fun with UIView.AnimateAsync()”

Hey mate, just wanted to thank you for this post. Cool idea, and helped me to think outside of the box as far as what async can be used for.

Hi Kerry,
did not know that you are in mobile development now. Were reading articles about Xamarin and nice to see your blog. When do you come to the US again? The Boston Red Socks had a great year and still remember our trip to the game….many years ago.
Greetings
Steffen

Doesnt this code in the end (after compiler unwraps all those awaits) become a huge clusterfuck of tasks and goto’s? Doesn’t it easier to just animate X position with something different than Linear progression?

Leave a Reply

Your email address will not be published. Required fields are marked *