Animate a Blocking Dialog in iOS
Today I was faced with a little challenge when I discovered that a blocking Help Dialog which should slide on and off does not animate after the user clicks OK.
It turns out that the UIView animation is executed in a background thread and so the method that is executed when the user clicks OK is processing further without waiting for the animation to finish. Within there I will yank the view from its parent and so the animation is not shown.
The solution to this is to register an Animation Delegate as well as the method that is called when the animation is done. This is done this way:
[UIView beginAnimations:@"hideView" context:NULL];
ATTENTION: Please note that these settings must be done within the animation block. Setting them outside means nothing is going to be happening.
This informs the given delegate when the animation is done and there is where I can release the block:
CFRunLoopStop( CFRunLoopGetCurrent() );
This will do the trick and allow me to clean up the dialog meaning removing it from the super view so that it will eventually released and not become a memory leak.
This little challenge also means that I finally become some sort of a iOS crack delving deeper and deeper into regions of iOS is never dared before to even have a look at it.
Cheers – Andy