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.
Asked
Active
Viewed 78 times
0
-
1Have you tried anything? – iphonic May 11 '17 at 05:48
-
tried NSTimer ?. Refer http://stackoverflow.com/questions/1449035/how-do-i-use-nstimer – Rince Thomas May 11 '17 at 05:56
-
@iphonic i tried for single image view and different images using NSTimer but for different image views i'm not getting the solution – May 11 '17 at 06:19
-
Did you set name for three imageViews? – user3182143 May 11 '17 at 08:31
2 Answers
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