0

I have 3 imageViews and 3 images. after 5sec of time interval i need to display first image in first image view and after next 5 sec second image in second image view and 3rd image in 3rd image view after 5 sec again.

2 Answers2

1

Try this,

First you declare

NSInteger currentPosition;

put this code in viewDidLoad

//initially give position as 1 for first image view
currentPosition = 1;
NSLog(@"Start");
timer = [NSTimer scheduledTimerWithTimeInterval:5
                                         target:self
                                       selector:@selector(targetMethod:)
                                       userInfo:nil
                                        repeats:YES];

and, write this function

-(void)targetMethod:(NSTimer *)timer
{
    if (currentPosition == 1) {
        firstImageView.image = [UIImage imageNamed:@"37240152-nature-desktop-wallpaper.jpg"];
        currentPosition = 2;
    }else if(currentPosition == 2){
        secondImageView.image = [UIImage imageNamed:@"37240152-nature-desktop-wallpaper.jpg"];
        currentPosition = 3;
    }else if(currentPosition == 3){
        thirdImageView.image = [UIImage imageNamed:@"37240152-nature-desktop-wallpaper.jpg"];
        currentPosition = 1;
    }
}
Subramani
  • 477
  • 2
  • 14
0

As I understand, you need something like Image Carousel,

t0
---
imageView1 = image1
imageView2 = image2
imageView3 = image3

t1
---
imageView1 = image3
imageView2 = image1
imageView3 = image2
...

If this is what you want, you can use a carousel with 3 images only and add a loop.

https://github.com/nicklockwood/iCarousel

You can find more items with, "image carousel" keyword.

Clown
  • 163
  • 1
  • 12