In this recipe, we will create a simple slideshow of images using the built-in animation feature of UIImageView
.
Create a new Single View Application in Xamarin Studio and name it ImageAnimationApp
. Add a UIImageView
and two buttons on the controller. The sample project for this task contains three images. Add two or more images to the project and make sure that their Build Action is set to Content.
Perform the following steps:
Enter the following code in the
ViewDidLoad
method:this.imgView.ContentMode = UIViewContentMode.ScaleAspectFit; this.imgView.AnimationImages = new UIImage[] { UIImage.FromFile("Kastoria.jpg"), UIImage.FromFile("Parga02.jpg"), UIImage.FromFile("Toroni.jpg") }; this.imgView.AnimationDuration = 3; this.imgView.AnimationRepeatCount = 10; this.btnStart.TouchUpInside += (sender, e) => { if (!this.imgView.IsAnimating) { this.imgView.StartAnimating(); } }; this.btnStop.TouchUpInside += (sender, e) => { if (this...