10876

Trying to change a UIImageView each 10 seconds

Question:

Well, I have a UIImageview in one of my views. I would like to change the image every 10 seconds, but I don't have any idea of how can I make it.

Any suggestion?

Answer1:

Create array of images first.

NSArray *images = [NSArray arrayWithObjects:[UIimage imagenamed:@"image1.png"],[UIimage imagenamed:@"image2.png"],[UIimage imagenamed:@"image3.png"],[UIimage imagenamed:@"image4.png"]]];

Then set array to UIImageViews "animationImages"property

imageView.animationImages = images;

Set time for animation.

imageView.animationDuration = 10;

Start animation..

[imageView startAnimating];

To stop animation just do this

[imageView stopAnimating];

Pretty simple..

Answer2:

You will need to use timer.

NSTimer *timer = [NSTimer timerWithTimeInterval:10 target:self selector:@selector(changeImage) userInfo:nil repeats:true];

and implement method for changing image:

- (void) changeImage { imageView.image = newImage; }

You can put this timer into ViewController containing your ImageView or you you can subclass ImageView and let it manage its image itself (especially useful if there are more independent imageview that need to change its image

Recommend

  • How to create a view which contain image and text as like newspaper has?
  • iOS performSelectorOnMainThread with multiple arguments
  • How to design code architecture when overlapping objects exist?
  • setImageresource in android - how to use it for many pictures in a loop
  • photo load order mess up as3
  • UIScrollview make the current Image Larger
  • CKEditor4 EnhancedImage Plugin Image added event or: How to add custom class to image
  • Trying to understand custom fields in WordPress
  • Image Slider with UIScrollView
  • openCV template matching using CV_TM_CCORR_NORMED
  • Why multiple constructor calls in a non MonoBehaviour class?
  • How to get the initial value of style properties in javascript? [duplicate]
  • What does “~/” resolve to in ASP: the current folder or the root of the website?
  • MediaPlayer.OnCompletionListener and View.OnClickListener?
  • Proper Syntax for 3 table SELECT query
  • how read-through work in ignite
  • Can I change the classname in a script when I change page
  • How to display Bitmap Image in image control on WPF using C#
  • Attempting to add a simple image into a label
  • Ajax 419 status error in laravel
  • ListView performance is slow
  • how to passing listview images passing another activity [closed]
  • didSelectRowAtIndexPath method at PFQueryTableViewController
  • Android how to set a transparent image resource of a view? or Remove the image?
  • Reinitialise existing jQuery flexslider with new options
  • I have a modal that opens a second modal and cannot close the first modal if open then close the sec
  • Where to put clearQueue in jQuery code
  • How to get a android ListView item selector to use state_pressed
  • Picasso Taking time to load images
  • div fade-in when window is scrolled a certain distance from the top
  • Floated image with variable width and heading with background image
  • How to have background script and something similar to a default popup?
  • Python urlparse: small issue
  • How to set my toolbar fixed while scrolling android
  • GridView Sorting works once only
  • How to set the response of a form post action to a iframe source?
  • Change div Background jquery
  • Qt: Run a script BEFORE make
  • reshape alternating columns in less time and using less memory
  • Android Heatmap on canvas or ImageView