Creating an animated spinner in a Xamarin.iOS (MonoTouch) UIImageView
Background I’m well into my first week of building the Sierra Trading Post first iOS app using Xamarin.iOS and it has been a fun ride so far. One of the first things needed was a system for showing a loading image while asynchronously retrieving the final image with a web request. Attempt 1 Xamarin has a recipe for using a UIImageView‘s AnimationImages to make a spinner. UIImageView someImageView = new UIImageView(); someImageView.AnimationImages = new UIImage[] { UIImage.FromBundle(“Spinning Circle_1.png”), UIImage.FromBundle(“Spinning Circle_2.png”), UIImage.FromBundle(“Spinning Circle_3.png”), UIImage.FromBundle(“Spinning Circle_4.png”), }; someImageView.AnimationRepeatCount = 0; // Repeat forever. someImageView.AnimationDuration = 1.0; // Every 1s. someImageView.StartAnimating(); It may be possible to make this work, but it wasn’t quite what I needed. This seems to be more of an image rotation than an animation. As a result, it creates a jerky animation between the various images equally distributed over the AnimationDuration you set. After this, attempts to find some ideas for a better solution lead me to about a hundred lines of code that proved a difficult to consume, involving a CGBitmapContext and CGAffineTransform.MakRotation. (To be fair, this code isn’t doing something as simple as what I want to do.) Hoping to avoid that, I simply added four more… Continue reading