I'm looking for a method that is an easy and straightforward way to delay execution for a number of frames in an iOS app, is this possible at all ?
Depending on the complexity of what you're doing, this small snippet could suffice:
double delayInSeconds = 2.0;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
//code to be executed on the main queue after delay
});
Otherwise you could look into NSTimer
to schedule some code to be executed. You can even repeat once or many times.
Can be used like this for example:
[NSTimer scheduledTimerWithTimeInterval:5.0
target:self
selector:@selector(myMethod)
userInfo:nil
repeats:NO];
For a great answer with a lot more info on how to use it, check out this post and of course, check out the documentation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With