Book Image

iOS Development with Xamarin Cookbook

By : Dimitrios Tavlikos (USD)
Book Image

iOS Development with Xamarin Cookbook

By: Dimitrios Tavlikos (USD)

Overview of this book

Table of Contents (22 chapters)
iOS Development with Xamarin Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Animating images


In this recipe, we will create a simple slideshow of images using the built-in animation feature of UIImageView.

Getting ready

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.

How to do it...

Perform the following steps:

  1. 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...