Animation a UIButton while animating a View - Ipad

Discussion in 'iPhone/iPad Programming' started by ashwinr87, May 24, 2011.

  1. macrumors member

    Joined:
    Mar 9, 2011
    #1
    Hi,

    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
    Code:
    [[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

    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.
     
  2. Shawnpk, May 24, 2011
    Last edited: May 24, 2011

    macrumors 6502

    Joined:
    Jan 13, 2011
    Location:
    Los Angeles, CA
    #2
  3. thread starter macrumors member

    Joined:
    Mar 9, 2011
    #3
    thanks for the link.. will check it out and see if I can get something to work...

     
  4. thread starter macrumors member

    Joined:
    Mar 9, 2011
    #4
    Here is how I solved it...

    many thanks to Shawnpk for pointing me at the right direction

    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...

    Code:
    [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];
                        }];
     

Share This Page