Skip to content

January 31, 2011


Animate a Blocking Dialog in iOS

by Andreas Schaefer

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];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector

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:

- (void)animationDidStop:(NSString*)animationID
                 context:(void *)context
    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

Read more from xcode
1 Comment
  1. Apr 25 2011

    I like the look of your blog! It looks really awesome.

Comments are closed.