Make the application wait a few seconds before executing the code?

I am trying to implement a way to take a screenshot in my application. I want the UINavigationBar tooltip to slide up - take a screenshot, and then the UINavigationBar can slide down well and easily. I need an application to wait / hold for a few seconds between some lines of code, because this way the first animation does not have time to finish:

[self.navigationController setNavigationBarHidden:YES animated:YES ]; [self.navigationController setNavigationBarHidden:NO animated:YES]; 

So, there is a way to delay execution, for example, when animating such a button:

 [UIView animateWithDuration:0.5 delay:3 options:UIViewAnimationOptionCurveEaseOut animations:^{self.myButton.frame = someButtonFrane;} completion:nil]; 

considers

+7
ios
source share
3 answers

You can use:

 [self performSelector:@selector(hideShowBarButton) withObject:nil afterDelay:1.0]; 

and of course:

 - (void) hideShowBarButton{ if (self.navigationController.navigationBarHidden) [self.navigationController setNavigationBarHidden:NO animated:YES ]; else [self.navigationController setNavigationBarHidden:YES animated:YES ]; } 
+3
source share

You can use:

 double delayInSeconds = 2.0; // number of seconds to wait dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC); dispatch_after(popTime, dispatch_get_main_queue(), ^(void){ /*********************** * Your code goes here * ***********************/ }); 
+11
source share

Until a callback is made to complete setNavigationBarHidden , it will take UINavigationControllerHideShowBarDuration seconds. So just use NSTimer to NSTimer it:

 [NSTimer scheduledTimerWithTimeInterval:UINavigationControllerHideShowBarDuration target:self selector:@selector(myFunction:) userInfo:nil repeats:NO]; 

You might want to add a small amount to the delay as fault tolerant;

 [NSTimer scheduledTimerWithTimeInterval:UINavigationControllerHideShowBarDuration+0.05 target:self selector:@selector(myFunction:) userInfo:nil repeats:NO]; 

See also this related question: UINavigationControoller - setNavigationBarHidden: animated: how to synchronize other animations

0
source share

All Articles