I have following scenario :
dispatch_after_delta(0.1, ^{
[self checkForTodaysBonus]; // It contains animation methods.
});
And
-(void) checkForTodaysBonus {
// Prepare View and other data and then animate UIView
[Animations moveDown:self.view andAnimationDuration:0.3 andWait:YES andLength:self.view.frame.size.height];
}
where, moveDown method is like :
+ (void) moveDown: (UIView *)view andAnimationDuration: (float) duration andWait:(BOOL) wait andLength:(float) length{
__block BOOL done = wait; //wait = YES wait to finish animation
[UIView animateWithDuration:duration animations:^{
view.center = CGPointMake(view.center.x, view.center.y + length);
} completion:^(BOOL finished) {
// This never happens if I call this method from dispatch_after.
done = NO;
}];
// wait for animation to finish
// This loop will allow wait to complete animation
while (done == YES) { // Application unable to break this condition
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.01]];
}
}
And
void dispatch_after_delta(float delta, dispatch_block_t block){
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, delta * NSEC_PER_SEC), dispatch_get_main_queue(), block);
}
So, issue, whenever animation
method is called from dispatch_after_delta
, animation
method never gets its completion block
.
What could be possible solution ?