Objective c 按下UILabel按钮后,UILabel将显示3秒钟
点击暂停按钮后,我希望在用户点击屏幕之前显示一个标签。我该怎么做 到目前为止,我有这个Objective c 按下UILabel按钮后,UILabel将显示3秒钟,objective-c,cocoa-touch,uilabel,nstimer,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 invalid
- (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];
}
}
}
试着跟随
[your_view addSubview:your_label];
your_label.hidden = YES;
[your_label performSelector:@selector(setHidden:) withObject:@NO afterDelay:3];
试着这样做:
-(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的视图上添加一个点击手势,如果显示了暂停标签并且在视图上发生了触摸,请检查其状态是否已结束并用动画隐藏标签。dispatch\u after(dispatch\u time(dispatch\u time)(int64\t)(3.0*NSEC\u PER\u SEC)),dispatch\u get\u main\u queue()^{
PauseLabel.hidden=是;
}); 使用
NSTimer
执行以下操作it@Avt,谢谢,这对我很管用。我甚至不知道您使用的performSelector方法。
-(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];
}];
}
}