开发者

Animating UIView while pushing a UINavigationController

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" Viewcontrolle开发者_StackOverflow社区r 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

Animating UIView while pushing a UINavigationController

Animating UIView while pushing a UINavigationController

Animating UIView while pushing a UINavigationController

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


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];
                     }];

}


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜