Animation after Dismissing a Modal View Does Not Work

790 Views Asked by At

I am trying to run the below animation--it fires right after I kill a modal view controller and return to my main screen. I am animating a UIImageView (activeThumbnail) to give the illusion of the modal view shrinking back to a certain place on the screen. Once the animation is done, I make thumbnail invisible by setting its alpha to 0. Seems simple enough, and I used this kind of animation a hundred times befor.

The problem is that, this time, when I put the alpha changing line in the "finished" block, the animation doesn't fire; it just jumps right to the finished block and dims my UIImageView instantly. Interestingly, when I comment that line out, the animation runs as expected. Here is the mentioned animation block:

[self dismissViewControllerAnimated:NO completion:nil];

[UIView animateWithDuration:0.4f
                      delay:0.0f
                    options: UIViewAnimationOptionCurveEaseInOut
                 animations:^{
                     activeThumbnail.frame = CGRectMake(activeThumbnailFrame.x, activeThumbnailFrame.y, 60.0f, 60.0f);
                 }
                 completion:^(BOOL finished)
                    {
                        //activeThumbnail.image = nil;
                        //activeThumbnail.alpha = 0.0f;
                    }];

Can someone point out what I am missing here?

Update: I did some experimenting and found out that the problem lies within the line that dismisses the modal view controller. It somehow gets mixed up with the animation's completion block. When I move my animation block to a separate method and call it from the dismiss command's completion block, it runs as expected:

completion:^{[self animationMethod];}

The problem with this is that it takes about two seconds for the completion block of the dismiss line to fire even with the animation set to NO. I am still puzzled as to how to solve this problem.

1

There are 1 best solutions below

0
On

If you are using storyboards you should consider something like this example

If you are not using storyboards then you may be able to adapt the example in the linked article to work by setting the parent viewController as a property on the child, and attempting to perform the animation in the same way the unwind animation is used.