Eri*_*rik 55 iphone animation uiviewcontroller uikit uinavigationcontroller
我想在推送视图控制器时显示自定义动画:我希望实现像"扩展"动画这样的东西,这意味着新视图从给定的矩形扩展,让动画期间[100,100 220,380]全屏显示.
任何建议从哪里开始,分别是任何文档,教程,链接?:)
好的.我可以使用以下代码制作展开动画:
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];
Run Code Online (Sandbox Code Playgroud)
我的视图已正确显示,但遗憾的是导航栏未更新.有没有办法手动完成?
在示例代码中,一个函数被称为0.03秒,用于更新视图的转换.不幸的是,当推动一个时UIViewController,我无法调整视图的框架...我是吗?
zou*_*oul 53
我使用以下函数(添加到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];
}
Run Code Online (Sandbox Code Playgroud)
我想你可以调整这段代码来做你想做的任何动画.
fya*_*sar 34
您正在寻找的代码:
[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];
Run Code Online (Sandbox Code Playgroud)
imn*_*mnk 25
您可以做的是推送下一个视图控制器,但不要为其设置动画,如下所示:
[self.navigationController pushViewController:nextController animated:NO];
Run Code Online (Sandbox Code Playgroud)
...然后,在推入的视图控制器中,您可以使用CoreAnimation对其视图进行自定义动画.这可能最好在viewDidAppear:(BOOL)animated方法中完成.
查看核心动画指南,了解如何实际制作动画.特别注意隐式动画.
编辑: 更新链接
小智 7
@zoul:这很棒!我只是将"self"更改为"self.navigationController",将"self.view"更改为"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];
Run Code Online (Sandbox Code Playgroud)
然后我只是调整了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];
}
Run Code Online (Sandbox Code Playgroud)
请注意,在动画之后,popViewController调用已下移到结尾.不知道那是不是犹太洁食,但又一次,它起作用了.
| 归档时间: |
|
| 查看次数: |
69951 次 |
| 最近记录: |