我正在开发一个儿童应用程序,需要在几秒钟后让答案消失 我需要添加什么?
- (IBAction)calculate2:(id)sender
{
float aaaa = 6;
Answer2.text = [ [NSString alloc] initWithFormat:@"%.0f ",aaaa];
}
答案 0 :(得分:0)
-(void) hideLabel
{
[Answer2 setHidden:YES];
}
只需将[self performSelector:@selector(hideLabel) withObject:nil afterDelay:4]
添加到calculate2
答案 1 :(得分:0)
为了隐藏它非动画,它将是:
[label setHidden:YES];
但如果你想用动画隐藏它,可能是:
[UIView animatedwithduration:1.0f delay:.35f animations:{
label.alpha = 0.0;
}completion:{
[label removeFromSuperview];
//Here you can put a completed code
}];
希望它有所帮助!
答案 2 :(得分:0)
使用NSTimer
并提及UILabel
指定的时间消失:
- (IBAction)calculate2:(id)sender
{
float aaaa = 6;
Answer2.text = [[NSString alloc] initWithFormat:@"%.0f ",aaaa];
[NSTimer scheduledTimerWithTimeInterval:2.0
target:self
selector:@selector(targetMethod:)
userInfo:nil
repeats:NO];
}
-(void)targetMethod:(NSTimer*)timer
{
//toggle hidden parameter
[Answer2 setHidden:!Answer2.hidden];
}