Question

I am facing a problem in animation.

So right now in my app, I have a subview which has a close button. When the close button is pressed, a curl down animation occurs showing the previous view. That is working properly. I perform the curl down closing animation by passing a notification to the NSNotificationCenter like this [[NSNotificationCenter defaultCenter] postNotificationName:notificationName object:self];

Now I wanted to apply an animation to the close button itself so that when I press the close button, it would perform an animation as well as the curl down animation would occur. So the way I do it is by the following code

[UIView transitionWithView:self.view.superview duration:1
                       options:UIViewAnimationOptionCurveEaseIn
                    animations:^ {
                        closeButton.frame = CGRectMake(500, 15, 100, 40); }
                    completion:nil];

Where previously the closeButton.frame had the value of (580,15,100,40) so the animation would be like the image was moving from right to left from 580 to 500.

So what happens when I run the code is that when I press the close button, the close button animation does not happen but the curl down animation occurs. So for testing when I commented out the code where I post the notification, the close button animation works perfectly but the curl down animation does not happen nor does the previous view come up ( since I do not send a notification which would cause the view to close).

I would like to know what is going wrong here and why it does not allow 2 animations to occur at the same time.

Was it helpful?

Solution

Here is how I solved it...

I used the nested animation using blocks where I included the code for the curl down close view in the completion part of the close button animation...

[UIView transitionWithView:self.view.superview duration:1
                       options:UIViewAnimationOptionCurveEaseIn
                    animations:^ {
                        popContents.closeButton.frame = CGRectMake(500, 15, 100, 40); }
                    completion:^(BOOL finished){
                        [UIView transitionWithView:self.view.superview duration:1
                                           options:UIViewAnimationOptionTransitionCurlDown
                                        animations:^ {
                                            popContents = nil;
                                            [popContents.view removeFromSuperview];
                                            [ovController.view removeFromSuperview];
                                            ovController = nil; }
                                        completion:nil];
                    }];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top