Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Animating images in ImageView

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 823
    Comment on it

     ImageView can be used for animation with a set of multiple images using various properties offered by apple.

     

    Here are I’m going to tell you steps to animate images in ImageView:

     

    1- Initialise an array of UIImage type.

    var arrayAllImages = [UIImage]()

     

    2- Start the loop and append every image(that you want to be animated) to array initialised in step 1.

    	for itemIndex in 1totalImages {
    
    		let imageName = YourImageName
    		let image = UIImage(named:imageName)
    		arrayAllImages.append(image)
     	}

     

    3- Now assign the image array as animation images to UIImageView object.

    imageView.animationImages = arrayAllImages

    You can use various properties of UIImageView to have animation:

    imageView.animationDuration = duration //default is 1/30 of a seconds
    imageView.animationRepeatCount = repeatCount // default is 0, which means infinite.

     

    4- Now Start animation for images  assigned in step 3.

    imageView.startAnimating()

    You can stop the animation using stopAnimation code. But it’s best to check in advance if an imageView is being animated or not before calling stop function.
     

    if imageView.isAnimating() {
                
        imageView.stopAnimating()    
     }
    

     

    Code Snippet

    	var arrayAllImages = [UIImage]()
    	for itemIndex in 1maxImages {
    
    		let imageName = YourImageName
    		let image = UIImage(named:imageName)
    		arrayAllImages.append(image)
     	}
    	imageView.animationImages = arrayAllImages
    	imageView.animationDuration = duration //default is 1/30 of a seconds
    	imageView.animationRepeatCount = repeatCount // default is 0
    	imageView.startAnimating()


     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: