Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making the app wait a few seconds before executing code?

Tags:

ios

Im trying to implement a way of taking a screenshot in my application. I want the UINavigationBar tip slide up - take the screenshot - and then the UINavigationBar can slide down nice and easy. I need the app to wait/hold a few seconds between some lines of code, because this way the first animation does not get time to finish:

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

So, is there a way of delaying execution, like when animation a button like so:

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

regards

like image 565
Anders Avatar asked Sep 29 '13 15:09

Anders


1 Answers

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 *
     ***********************/
});    
like image 129
vitaluha Avatar answered Nov 07 '22 01:11

vitaluha