UIImage 的图像随时间变化
我想更改 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试:
performSelector
安排选择器调用,并延迟一些。它不会延迟当前方法的执行Try:
performSelector
schedules selector call with some delay. It does not delay the execution of current method您也可以发布
doNothing
的代码吗?如果
doNothing
确实什么都不做,那么所发生的情况是doNothing
方法在以下行执行后 3 秒后被调用:But 事情是这样的,在您的
doNothing
方法被计划三秒后运行后,将立即执行以下行:换句话说,方法执行不会等待您的
doNothing
方法完成,它只是继续,并且doNothing
在单独的线程上运行。Could you post the code for
doNothing
too please?If
doNothing
really does nothing, then what's happening is thedoNothing
method is being called after 3 seconds from when the following line executes:But here's the thing, the following line is being executed straight after your
doNothing
method has been scheduled to run after three seconds:In other words, the method execution doesn't wait around for your
doNothing
method to complete, it just continues, anddoNothing
is run on a separate thread.您已经说过在延迟 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.