在每5秒的时间间隔后在图像视图中显示图像

时间:2021-09-17 02:52:13

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.

我有3个imageViews和3个图像。在5秒的时间间隔之后,我需要在第一图像视图中显示第一图像,并且在第二图像视图中显示下一个5秒的第二图像,并且在5秒之后再次显示第三图像视图中的第三图像。

2 个解决方案

#1


1  

Try this,

尝试这个,

First you declare

首先你宣布

NSInteger currentPosition;

put this code in viewDidLoad

将此代码放在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;
    }
}

#2


0  

As I understand, you need something like Image Carousel,

据我所知,你需要像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.

如果这是你想要的,你可以使用只有3张图像的旋转木马并添加一个循环。

https://github.com/nicklockwood/iCarousel

https://github.com/nicklockwood/iCarousel

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

您可以在“image carousel”关键字中找到更多项目。

#1


1  

Try this,

尝试这个,

First you declare

首先你宣布

NSInteger currentPosition;

put this code in viewDidLoad

将此代码放在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;
    }
}

#2


0  

As I understand, you need something like Image Carousel,

据我所知,你需要像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.

如果这是你想要的,你可以使用只有3张图像的旋转木马并添加一个循环。

https://github.com/nicklockwood/iCarousel

https://github.com/nicklockwood/iCarousel

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

您可以在“image carousel”关键字中找到更多项目。