문제

I am working on a kids app and need to make the answer disappear after a few seconds.
What do I need to add?

- (IBAction)calculate2:(id)sender
{     
    float aaaa = 6;     
    Answer2.text = [ [NSString alloc] initWithFormat:@"%.0f ",aaaa];      
}
도움이 되었습니까?

해결책

Use NSTimer and mention the specified time for UILabel to disappear:

- (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];
}

다른 팁

-(void) hideLabel
{
      [Answer2 setHidden:YES];
}

just add [self performSelector:@selector(hideLabel) withObject:nil afterDelay:4] to calculate2

For hiding it non-animated it will be:

[label setHidden:YES];

But if you want to hide it with an Animation it could be:

[UIView animatedwithduration:1.0f delay:.35f animations:{

label.alpha = 0.0;


}completion:{
[label removeFromSuperview];
//Here you can put a completed code
}];

Hope it helps!

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top