IOS app shutdown

I'm looking for a way that is a simple and easy way to delay execution for multiple frames in an iOS application, is this even possible?

+4
source share
4 answers

You can use the [NSTimer scheduledTimerWithTimeInterval: target: selector:] method, and also use the built-in method like wait(time_in_seconds); .
Hope this helps you.

+1
source

Depending on the complexity of what you are doing, this small snippet may be enough:

 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 can take a look at NSTimer to schedule some code to run. You can even repeat one or more times.

It 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 much more information on how to use it, check out this post and, of course, check the documentation .

+10
source

If you mean some constant time, the general way to do this is to use NSTimer to start in the future or use dispatch_after (), which can send a block either to the main queue or at some point in the future.

+2
source

David is right. Here is some code to use NSTimer.

 -(void)startAnimating { [NSTimer scheduledTimerWithTimeInterval:.3 target:self selector:@selector(animateFirstSlide) userInfo:nil repeats:NO]; self.pageTurner = [NSTimer scheduledTimerWithTimeInterval:6.0 target:self selector:@selector(turnPages) userInfo:nil repeats:YES]; } -(void)animateFirstSlide { [self animateSlideAtIndex:0]; } -(void)stopPageTurner { [self.pageTurner invalidate]; } 
+2
source

Source: https://habr.com/ru/post/1484895/


All Articles