在推送 UINavigationController 时为 UIView 制作动画

发布于 2024-11-05 07:57:55 字数 1374 浏览 0 评论 0原文

以下情况。 我有一个使用 UINavigationController 进行导航的应用程序。

为了推动特殊的导航控制器,我想要一个自定义动画,一个缩小。 到目前为止,我所拥有的看起来不错,唯一的问题是,“旧”视图控制器在动画开始之前消失,因此新视图控制器会缩小“无”,而不是在后台查看旧视图控制器。

为了更好地观看,我创建了一个简单的示例应用程序: 下载

在此处输入图像描述在此处输入图像描述在此处输入图像描述

有谁知道如何为旧视图控制器(image1) 的新视图控制器(image3) 制作动画动画时留在后台(图 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];

附加信息:我的应用程序并不那么简单。我在我的应用程序中使用 Three20 框架,但是视图控制器的推送和创建就是 Three20 所做的。我只能连接到(THIS CAN BE CHANGED 在我的代码中)之间的部分。我无法在此之前和之后更改代码(除非进行大量研究)。

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

似最初 2024-11-12 07:57:55

我很快就想到了这个。想法是在缩放动画完成后调用pushViewController。

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

}

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

}
薄荷→糖丶微凉 2024-11-12 07:57:55

好的,一种方法(有点难看)是执行动画,并在动画完成后执行pushViewController。当您制作动画时,您需要对即将呈现的视图控制器的屏幕进行动画处理。由于动画以新视图结束,因此当新视图出现在屏幕上时,不应发生任何变化,因为它与刚刚动画的视图相同。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文