1

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.

3
  • Stupid question: Have you tried adding NSLogs to both the completion and the animation to see if it is in fact firing out of order? This won't fix the issue, but it might help troubleshoot it.
    – Aron C
    Dec 9, 2014 at 21:07
  • Actually, I did not. I will try when I get home today. Dec 10, 2014 at 6:32
  • I updated the original post with new info. By the way I checked and those sections do indeed fire. The problem lies in the dismissing of the modal view. Dec 11, 2014 at 14:36

1 Answer 1

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.