2011-07-18 90 views
0

我想设置一个图像的UIButton设置的时间的一些图像,然后在那段时间后,我希望按钮来删除图片。这是我一直在使用的代码,它不是工作的接缝。如果有人能帮忙,我会非常感激!如何设置图像的UIButton,并随后将其删除(动画)

谢谢!

[UIView animateWithDuration:5.0 animations:^{ 
    [button setImage:[UIImage imageNamed:@"light.png"] forState:UIControlStateNormal]; 

}completion:^(BOOL finisheds){ 
    [button setImage:nil forState:UIControlStateNormal; 
}]; 

回答

1

如果你定义在类中的方法,像这样:

- (void)removeImageFromButton:(id)button { 
    [button setImage:nil forState:UIControlStateNormal] 
} 

然后,你可以做你想做的事是这样的:同样

[button setImage:[UIImage imageNamed:@"light.png"] forState:UIControlStateNormal]; 
[self performSelector:@selector(removeImageFromButton:) withObject:button afterDelay:5.0]; 

,你可能想要在- (void)dealloc中添加[NSObject cancelPreviousPerformSelectorRequestsWithTarget:self];,否则如果在5s启动之前self被释放,您将获得EXC_BAD_ACCESS

相关问题