如何连续随机选择任意网点?

发布于 2024-10-17 04:48:51 字数 619 浏览 3 评论 0原文

(我有六个图像视图,我想将其中的图像随机动画两秒钟。)

朋友们您好,
我有六个图像视图,在一个视图中具有不同的静态图像,我希望它们在方法的帮助下进行动画处理

img1.animationImages = [NSArray arrayWithObjects:   
                                    [UIImage imageNamed:imgName],
                                    [UIImage imageNamed:imgName2],
                                    [UIImage imageNamed:imgName],
                                    [UIImage imageNamed:imgName2],
                                    [UIImage imageNamed:imgName],
                                    [UIImage imageNamed:imgName2],

,并且我想随机选择图像视图两秒钟。

最好的方法是什么?

(I have six image view and I want to animate the image randomly for two seconds among them.)

Hello Friends ,
I have six image view with different static images in one view and I want them to animate with the help of

img1.animationImages = [NSArray arrayWithObjects:   
                                    [UIImage imageNamed:imgName],
                                    [UIImage imageNamed:imgName2],
                                    [UIImage imageNamed:imgName],
                                    [UIImage imageNamed:imgName2],
                                    [UIImage imageNamed:imgName],
                                    [UIImage imageNamed:imgName2],

method and I want to select the imageview randomly for two seconds.

What is the best way to do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

↙温凉少女 2024-10-24 04:48:51

好吧,从 0,1,2,3,4,5 中选择一个随机数,只需执行此操作

randomNumber = arcRandom() % 6;

即可“显示两秒”,您需要了解 NSTimer。这很简单。这是一个简单的定义,它将在一段时间内执行某些操作:

#define SCHED( T, S )                                               \
    [NSTimer scheduledTimerWithTimeInterval:T                       \
        target:self selector:@selector(S) userInfo:nil repeats:NO]

例如:

SCHED( 2.0, eliminateImage );
SCHED( 0.5, fadeToBlack );

在每种情况下,您都必须编写例程“eliminateImage”或“fadeToBlack”。

Well to pick a random number from 0,1,2,3,4,5, just do this

randomNumber = arcRandom() % 6;

To "display for two seconds" you need to learn about NSTimer. It is quite simple. Here is a simple define that will do something in a period of time:

#define SCHED( T, S )                                               \
    [NSTimer scheduledTimerWithTimeInterval:T                       \
        target:self selector:@selector(S) userInfo:nil repeats:NO]

So for example:

SCHED( 2.0, eliminateImage );
SCHED( 0.5, fadeToBlack );

in each case you would have to write the routine "eliminateImage" or "fadeToBlack".

新人笑 2024-10-24 04:48:51

这可能对你有帮助。

imageArray = [[NSMutableArray alloc] initWithCapacity:IMAGE_COUNT];
for (int i = 1; i <= IMAGE_COUNT; i++)
    [imageArray addObject:[UIImage imageNamed:[NSString stringWithFormat:@"Image%d.png", i]]];


bgImage.animationImages = [NSArray arrayWithArray:imageArray];
bgImage.animationDuration = 9.0;
bgImage.animationRepeatCount = 0.0;
[self.view addSubview:bgImage];
bgImage.startAnimating;

this may help you.

imageArray = [[NSMutableArray alloc] initWithCapacity:IMAGE_COUNT];
for (int i = 1; i <= IMAGE_COUNT; i++)
    [imageArray addObject:[UIImage imageNamed:[NSString stringWithFormat:@"Image%d.png", i]]];


bgImage.animationImages = [NSArray arrayWithArray:imageArray];
bgImage.animationDuration = 9.0;
bgImage.animationRepeatCount = 0.0;
[self.view addSubview:bgImage];
bgImage.startAnimating;
旧时模样 2024-10-24 04:48:51

您可以使用随机索引从数组中选择图像:

int index = int index = rand()%[img1.animationImages count];

you can select images from array using random index:

int index = int index = rand()%[img1.animationImages count];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文