UILabel在按下UIButton后出现3秒钟

时间:2014-03-23 23:15:14

标签: objective-c cocoa-touch uilabel nstimer

点击暂停按钮后,我想要一个标签出现,直到用户点击屏幕。我该怎么做?

到目前为止,我有这个

- (IBAction)ButtonPausePressed:(id)sender {

 PauseLabel.hidden = false (//how do i make it only visible until user taps?//)

if (GameEnd != true){
    if ([GameUpdate isValid]){
        [GameUpdate invalidate];
        [BirdUpdate invalidate];
    }else{
        BirdUpdate = [NSTimer scheduledTimerWithTimeInterval:0.015
                                                      target:self
                                                    selector:@selector(UpdateBird)
                                                    userInfo:nil
                                                     repeats:YES];
        GameUpdate = [NSTimer scheduledTimerWithTimeInterval:0.025
                                                      target:self
                                                    selector:@selector(GameUpdate)
                                                    userInfo:nil
                                                     repeats:YES];
    }
}
}

4 个答案:

答案 0 :(得分:1)

尝试以下

[your_view addSubview:your_label];
your_label.hidden = YES;
[your_label performSelector:@selector(setHidden:) withObject:@NO afterDelay:3];

答案 1 :(得分:1)

- (IBAction)ButtonPausePressed:(id)sender { 
   PauseLabel.hidden = false
   [self performSelector:@selector(hiddenLabel) withObject:nil afterDelay:3];
   ...
}

- (void)hiddenLabel{
    PauseLabel.hidden = YES;
}

答案 2 :(得分:0)

试试这样:

-(void)viewDidLoad
{
        UITapGestureRecognizer *singleTapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(btnSingleClicked:)];

        [singleTapGesture setDelegate:self];
         singleTapGesture.numberOfTapsRequired = 1;
        [self.view addGestureRecognizer:singleTapGesture];
}

-(void)btnSingleClicked:(UITapGestureRecognizer *)recognizer
{
    if(recognizer.state == UIGestureRecognizerStateEnded && !self.PauseLabel.hidden)
    {
         [[UIApplication sharedApplication] beginIgnoringInteractionEvents];
         [UIView animateWithDuration:3.0f       // 3 sec to hide it
                          delay:0.0f
                        options:UIViewAnimationOptionCurveEaseOut
                     animations:^{
                         [self.PauseLabel setAlpha:0.0f];
                                 }
                     completion:^(BOOL finished)
                               {
                                   // remove from super view if needed.
                                   // Now you can handle touch events etc
                                   [[UIApplication sharedApplication] endIgnoringInteractionEvents];
                               }];
    }
}

该行背后的想法是在您的viewcontroller视图上添加一个单击手势,如果显示暂停标签并且在视图上发生触摸,则检查其状态是否已结束并使用动画隐藏标签。

答案 3 :(得分:0)

dispatch_after(dispatch_time(DISPATCH_TIME_NOW,(int64_t)(3.0 * NSEC_PER_SEC)),dispatch_get_main_queue(),^ {         PauseLabel.hidden = YES;     });