4
votes

following situation. i have an app that uses a UINavigationController for navigating.

For a push of a special Navigation Controller i want a custom Animation, a zoom out. What i have is looking good so far, the only problem is, that the "old" Viewcontroller disappears before the animation starts, so the new viewcontroller zooms out of "nothing" instead of viewing the old viewcontroller in the background.

For better viewing i created a simple sample app: download

enter image description hereenter image description hereenter image description here

Does anybody know, how to animate the new viewcontroller (image3) that the old view controller(image1) stays in the background while animating (image 2)?

/* THIS CANNOT BE CHANGED */
    AnimatedViewController *animatedViewController = [[AnimatedViewController alloc] initWithNibName:@"AnimatedViewController" bundle:nil];

    /* THIS CAN BE CHANGED */
    animatedViewController.view.transform = CGAffineTransformMakeScale(0.01, 0.01);
    [UIView beginAnimations:@"animationExpand" context:NULL];
    [UIView setAnimationDuration:0.6f];
    animatedViewController.view.transform=CGAffineTransformMakeScale(1, 1);
    [UIView setAnimationDelegate:self];
    [UIView commitAnimations];

    /* THIS CANNOT BE CHANGED */
    [self.navigationController pushViewController:animatedViewController animated:NO];

Additional information: my app isn't that simple. i use three20 framework for my app but the pushing and creating of the view controllers is simply what three20 does. i only can hook into the part between (THIS CAN BE CHANGED in my code). i cannot change the code before and after this (except with a lot of researching).

2
How set the same animation (revese direction) while pop to the original view..?iOS dev

2 Answers

9
votes

I whipped this up very quickly. The idea is to call pushViewController after the scale animation is completed.

-(IBAction)animateButtonClicked:(id)sender {
    animatedViewController = [[AnimatedViewController alloc] initWithNibName:@"AnimatedViewController" bundle:nil];
    animatedViewController.view.transform = CGAffineTransformMakeScale(0.01, 0.01);

    [UIView animateWithDuration:0.6
                     animations:^{
                         [self.view addSubview:animatedViewController.view];
                         animatedViewController.view.transform=CGAffineTransformMakeScale(1, 1);                     
                     }
                     completion:^(BOOL finished){ 
                         [animatedViewController.view removeFromSuperview];
                         [self.navigationController pushViewController:animatedViewController animated:NO];
                     }];

}
0
votes

Ok, one way to do this (a bit ugly) is to do the animation and upon the completion of the animation, do the pushViewController. When you do the animation, you need to animate up what the about-to-be-presented view controller's screen would look like. Since the animation ends with the new view, when the new view comes to the screen, nothing should change because its the same as the just animated view.