Reputation: 729
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
Upvotes: 7
Views: 4073
Reputation: 18470
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 ];
}
Upvotes: 3
Reputation: 183
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 *
***********************/
});
Upvotes: 11
Reputation: 46249
While there doesn't appear to be a callback for setNavigationBarHidden
's completion, it will take UINavigationControllerHideShowBarDuration
seconds. So just use a NSTimer
to delay it:
[NSTimer scheduledTimerWithTimeInterval:UINavigationControllerHideShowBarDuration target:self selector:@selector(myFunction:) userInfo:nil repeats:NO];
You may want to add a small amount to the delay as a fail-safe;
[NSTimer scheduledTimerWithTimeInterval:UINavigationControllerHideShowBarDuration+0.05 target:self selector:@selector(myFunction:) userInfo:nil repeats:NO];
See also this related question: UINavigationControoller - setNavigationBarHidden:animated: How to sync other animations
Upvotes: 0