I want to show a custom animation when pushing a view controller: I would like to achieve something like an "expand" animation, that means the new view expands from a given rectangle, lets say [100,100 220,380] during the animation to full screen.
我想在推动视图控制器时显示一个自定义动画:我想实现类似“展开”动画的东西,这意味着新视图从给定的矩形扩展,比方说[100,100 220,380]在动画期间扩展到全屏。
Any suggestions where to start, respectively any documents, tutorials, links? :)
有什么建议从哪里开始,分别有文档,教程,链接吗?:)
Alright. I could make the expand animation with the following code:
好吧。我可以用以下代码制作展开动画:
if ([coming.view superview] == nil)
[self.view addSubview:coming.view];
coming.view.frame = CGRectMake(160,160,0,0);
[UIView beginAnimations:@"frame" context:nil];
[UIView setAnimationDuration:4];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[coming viewWillAppear:YES];
[going viewWillAppear:YES];
coming.view.frame = CGRectMake(0, 0, 320, 480);
[going viewDidDisappear:YES];
[coming viewDidAppear:YES];
[UIView commitAnimations];
My View is properly displayed, but unfortunately the navigation bar is not updated. Is there a way to do that manually?
我的视图显示正确,但不幸的是导航栏没有更新。有办法手动完成吗?
In the sample code, a function is called all 0.03 seconds that updates the transformation of the view. Unfortunately, when pushing a UIViewController
, I am not able to resize the frame of the view ... am I ?
在示例代码中,一个函数被称为0.03秒,它更新视图的转换。不幸的是,当推一个UIViewController时,我不能调整视图的框架大小……我是吗?
7 个解决方案
#1
25
What you could do is push the next view controller but don't animate it, like so:
你所能做的就是推下一个视图控制器但不要让它动起来,像这样:
[self.navigationController pushViewController:nextController animated:NO];
...and then, in the view controller that is getting pushed in, you could do a custom animation of it's view using CoreAnimation. This might be best done in the viewDidAppear:(BOOL)animated
method.
…然后,在被推入的视图控制器中,你可以用CoreAnimation定制它的视图动画。这在viewDidAppear:(BOOL)动画方法中可能是最好的。
Check out the Core Animation Guide on how to actually do the animation. Look particularly at the implicit animation.
看看核心动画指南如何做动画。特别看看隐式动画。
EDIT: updated link
编辑:更新的链接
#2
52
I use the following function (added to UINavigationController
) to customize the push animation:
我使用以下功能(添加到UINavigationController)来定制推送动画:
- (void) pushController: (UIViewController*) controller
withTransition: (UIViewAnimationTransition) transition
{
[UIView beginAnimations:nil context:NULL];
[self pushViewController:controller animated:NO];
[UIView setAnimationDuration:.5];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationTransition:transition forView:self.view cache:YES];
[UIView commitAnimations];
}
I guess you could adapt this code to do whatever animation you want.
我猜你可以调整这段代码来做你想做的任何动画。
#3
34
The code which you are looking for:
您正在查找的代码:
[UIView beginAnimations:@"View Flip" context:nil];
[UIView setAnimationDuration:0.80];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition:
UIViewAnimationTransitionFlipFromRight
forView:self.navigationController.view cache:NO];
[self.navigationController pushViewController:menu animated:YES];
[UIView commitAnimations];
#4
10
Heinrich,
海因里希,
I have made a youtube tutorial showing how to make views expand and shrink, like in the facebook iPhone app.
我在youtube上做了一个教程,演示如何在facebook的iPhone应用程序中扩展和缩小视图。
Hope it can be of help: How to make expanding/shrinking views on iPhone SDK
希望它能有所帮助:如何在iPhone SDK上扩展/缩小视图。
Adam
亚当
#5
7
@zoul: That worked great! I just changed "self" to "self.navigationController" and "self.view" to "self.navigationController.view" Don't know if that was necessary, but it worked. And @crafterm, as for popping back, just make your own leftBarButtonItem by adding this code in viewDidLoad or ViewWillAppear:
@zoul:那工作好了!我把“我”改成了“我”。导航控制器”和“自我。“self.navigationController视图”。view"不知道是否有必要,但它确实有效。@crafterm,至于弹出窗口,只需在viewDidLoad或ViewWillAppear中添加此代码,创建自己的leftBarButtonItem:
//add your own left bar button
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:self action:@selector(backButtonTapped)];
self.navigationItem.leftBarButtonItem = backButton;
[backButton release];
Then I just tweaked the push function and made this popWithTransition function that I called in my -backButtonTapped method.
然后我对push函数进行了调整,并在-backButtonTapped方法中调用了这个popWithTransition函数。
- (void) popWithTransition: (UIViewAnimationTransition) transition
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:.75];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationTransition:transition forView:self.navigationController.view cache:YES];
[UIView commitAnimations];
[self.navigationController popViewControllerAnimated:NO];
}
Note that the popViewController call got shifted down to the end, after the animation. Don't know if that's kosher, but again, it worked.
注意,popViewController调用在动画之后被移动到最后。不知道这是否符合犹太教规,但它还是奏效了。
#6
3
What you want is the downloads for chapter 2 of iphone developers cookbook. Look at the affineRotate sample specifically, although any of the core animatin samples will help you.
你想要的是iphone开发者烹饪书第二章的下载。具体地看一下affineRotate示例,尽管任何核心的animatin示例都将对您有所帮助。
#7
3
Have a look at ADTransitionController, a drop in replacement for UINavigationController with custom transition animations (its API matches the API of UINavigationController) that we created at Applidium.
让我们来看看ADTransitionController,用我们在Applidium创建的自定义转换动画替换UINavigationController(它的API与UINavigationController的API相匹配)。
You can use different pre-defined animations for push and pop actions such as Swipe, Fade, Cube, Carrousel and so on. In your case, the animation you are requesting is the one called Zoom.
您可以使用不同的预定义动画来推动和弹出动作,比如滑动、淡出、立方体、旋转木马等等。在您的例子中,您请求的动画是一个叫做Zoom的动画。
#1
25
What you could do is push the next view controller but don't animate it, like so:
你所能做的就是推下一个视图控制器但不要让它动起来,像这样:
[self.navigationController pushViewController:nextController animated:NO];
...and then, in the view controller that is getting pushed in, you could do a custom animation of it's view using CoreAnimation. This might be best done in the viewDidAppear:(BOOL)animated
method.
…然后,在被推入的视图控制器中,你可以用CoreAnimation定制它的视图动画。这在viewDidAppear:(BOOL)动画方法中可能是最好的。
Check out the Core Animation Guide on how to actually do the animation. Look particularly at the implicit animation.
看看核心动画指南如何做动画。特别看看隐式动画。
EDIT: updated link
编辑:更新的链接
#2
52
I use the following function (added to UINavigationController
) to customize the push animation:
我使用以下功能(添加到UINavigationController)来定制推送动画:
- (void) pushController: (UIViewController*) controller
withTransition: (UIViewAnimationTransition) transition
{
[UIView beginAnimations:nil context:NULL];
[self pushViewController:controller animated:NO];
[UIView setAnimationDuration:.5];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationTransition:transition forView:self.view cache:YES];
[UIView commitAnimations];
}
I guess you could adapt this code to do whatever animation you want.
我猜你可以调整这段代码来做你想做的任何动画。
#3
34
The code which you are looking for:
您正在查找的代码:
[UIView beginAnimations:@"View Flip" context:nil];
[UIView setAnimationDuration:0.80];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition:
UIViewAnimationTransitionFlipFromRight
forView:self.navigationController.view cache:NO];
[self.navigationController pushViewController:menu animated:YES];
[UIView commitAnimations];
#4
10
Heinrich,
海因里希,
I have made a youtube tutorial showing how to make views expand and shrink, like in the facebook iPhone app.
我在youtube上做了一个教程,演示如何在facebook的iPhone应用程序中扩展和缩小视图。
Hope it can be of help: How to make expanding/shrinking views on iPhone SDK
希望它能有所帮助:如何在iPhone SDK上扩展/缩小视图。
Adam
亚当
#5
7
@zoul: That worked great! I just changed "self" to "self.navigationController" and "self.view" to "self.navigationController.view" Don't know if that was necessary, but it worked. And @crafterm, as for popping back, just make your own leftBarButtonItem by adding this code in viewDidLoad or ViewWillAppear:
@zoul:那工作好了!我把“我”改成了“我”。导航控制器”和“自我。“self.navigationController视图”。view"不知道是否有必要,但它确实有效。@crafterm,至于弹出窗口,只需在viewDidLoad或ViewWillAppear中添加此代码,创建自己的leftBarButtonItem:
//add your own left bar button
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:self action:@selector(backButtonTapped)];
self.navigationItem.leftBarButtonItem = backButton;
[backButton release];
Then I just tweaked the push function and made this popWithTransition function that I called in my -backButtonTapped method.
然后我对push函数进行了调整,并在-backButtonTapped方法中调用了这个popWithTransition函数。
- (void) popWithTransition: (UIViewAnimationTransition) transition
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:.75];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationTransition:transition forView:self.navigationController.view cache:YES];
[UIView commitAnimations];
[self.navigationController popViewControllerAnimated:NO];
}
Note that the popViewController call got shifted down to the end, after the animation. Don't know if that's kosher, but again, it worked.
注意,popViewController调用在动画之后被移动到最后。不知道这是否符合犹太教规,但它还是奏效了。
#6
3
What you want is the downloads for chapter 2 of iphone developers cookbook. Look at the affineRotate sample specifically, although any of the core animatin samples will help you.
你想要的是iphone开发者烹饪书第二章的下载。具体地看一下affineRotate示例,尽管任何核心的animatin示例都将对您有所帮助。
#7
3
Have a look at ADTransitionController, a drop in replacement for UINavigationController with custom transition animations (its API matches the API of UINavigationController) that we created at Applidium.
让我们来看看ADTransitionController,用我们在Applidium创建的自定义转换动画替换UINavigationController(它的API与UINavigationController的API相匹配)。
You can use different pre-defined animations for push and pop actions such as Swipe, Fade, Cube, Carrousel and so on. In your case, the animation you are requesting is the one called Zoom.
您可以使用不同的预定义动画来推动和弹出动作,比如滑动、淡出、立方体、旋转木马等等。在您的例子中,您请求的动画是一个叫做Zoom的动画。