UIImage 的图像随时间变化

发布于 2024-11-06 23:35:00 字数 354 浏览 0 评论 0原文

我想更改 UIImageView 的图像,3 秒后返回到第一张图像...这是我的代码:

-(void)change: (UIImageView *)sender
{
    UIImage *image = [UIImage imageNAmed: @"anImage"];
    [sender setImage:image];
    [self performSelector: @selector(doNothing) withObject:nil afterDelay:3];
    [sender setImage: [UIImage imageNamed: @"firstImage"]];
}

它不起作用。

I want to change an UIImageView's image and 3 seconds later go back to the first image...This is my code:

-(void)change: (UIImageView *)sender
{
    UIImage *image = [UIImage imageNAmed: @"anImage"];
    [sender setImage:image];
    [self performSelector: @selector(doNothing) withObject:nil afterDelay:3];
    [sender setImage: [UIImage imageNamed: @"firstImage"]];
}

It doesn't work.

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

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

发布评论

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

评论(3

雨夜星沙 2024-11-13 23:35:00

尝试:

-(void)change: (UIImageView *)sender
{
    UIImage *image = [UIImage imageNAmed: @"anImage"];
    [sender setImage:image];
    [sender performSelector: @selector(setImage:) withObject:[UIImage imageNamed: @"firstImage"] afterDelay:3];
}

performSelector 安排选择器调用,并延迟一些。它不会延迟当前方法的执行

Try:

-(void)change: (UIImageView *)sender
{
    UIImage *image = [UIImage imageNAmed: @"anImage"];
    [sender setImage:image];
    [sender performSelector: @selector(setImage:) withObject:[UIImage imageNamed: @"firstImage"] afterDelay:3];
}

performSelector schedules selector call with some delay. It does not delay the execution of current method

毁梦 2024-11-13 23:35:00

您也可以发布 doNothing 的代码吗?

如果 doNothing 确实什么都不做,那么所发生的情况是 doNothing 方法在以下行执行后 3 秒后被调用:

[self performSelector: @selector(doNothing) withObject:nil afterDelay:3];

But 事情是这样的,在您的 doNothing 方法被计划三秒后运行后,将立即执行以下行:

[sender setImage: [UIImage imageNamed: @"firstImage"]];

换句话说,方法执行不会等待您的 doNothing 方法完成,它只是继续,并且 doNothing 在单独的线程上运行。

Could you post the code for doNothing too please?

If doNothing really does nothing, then what's happening is the doNothing method is being called after 3 seconds from when the following line executes:

[self performSelector: @selector(doNothing) withObject:nil afterDelay:3];

But here's the thing, the following line is being executed straight after your doNothing method has been scheduled to run after three seconds:

[sender setImage: [UIImage imageNamed: @"firstImage"]];

In other words, the method execution doesn't wait around for your doNothing method to complete, it just continues, and doNothing is run on a separate thread.

拥抱影子 2024-11-13 23:35:00

您已经说过在延迟 3 秒后执行 doNothing 函数。因此 3 秒后它将被调用,因此在 doNothing 函数中将图像更改回firstImage。

you have said to perform the function doNothing after 3 seconds of delay. So after 3 seconds it will get called so change the image back to firstImage in doNothing function.

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