Dispatch_after and [UIView animation: duration] occur immediately (but should not)

With iOS7 we get an intermittent error. This did not happen with iOS6.

It does not start immediately, but ~ 30 seconds to ~ 2 minutes in the game, ALL animations and dispatch_after commands occur instantly.

To be more specific, the animation happens as if the "duration:" value is 0, although it is definitely not 0. To be more specific, dispatch_after happens as if wait = 0.

Once it starts, it is saved until the software is completed.

I do not know how to debug this, or if it is an iOS7 error. Any thanks / help would be greatly appreciated!

+6
source share
3 answers

Is there a problem that you think your completion block is being called prematurely?

If so, have you checked the value of the boolean passed to the completion block? You can only execute instructions in this block if the boolean value is true.

eg.

[UIView animateWithDuration... animations:^{ //do something } completion:^(BOOL finished) { if (finished) { // do something } }]; 

I saw this when the completion block was called before the animation even started, but it was actually because something else canceled the animation, hence finished = NO .

This does not answer the dispatch_after question, so you can still find the error there.

+1
source

The question title and descriptions seem different (fuzzy to understand), anyway, if you want to complete the task after some time, look below

dispatch_after and [UIView animation: duration] occur immediately

This might work:

 // Do your stuff OR animations then use below for DISPATCH_AFTER... double delayInSeconds = 2.0f; dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC)); dispatch_after(popTime, dispatch_get_main_queue(), ^(void){ // Do your Stuff Or Add Animation [UIView animateWithDuration:.6f animations:^{ self.tableView.contentOffset = CGPointMake(0, 173); }]; }); 
0
source

Your question sounds like you are not invoking animations and feeds in the main thread . This leads to unexpected behavior, such as viewing, not being updated or moving until a certain point in time.

Try moving the animation block inside dispatch_main like this:

 dispatch_async(dispatch_get_main_queue(), ^{ <# Code #> }); 

and see if it fixes the problem.

0
source

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


All Articles