简体   繁体   English

iPhone dev:如何控制视图过渡动画?

[英]iphone dev: how to control the view transition animation?

I am using such code to present a new view, I don't it's good or not. 我正在使用这样的代码来呈现新的观点,这不是好事。 Currently the default animation is show the view from bottom up, but i want it to animate from right to left(fly in), is it possible to change the default animation type and how? 当前默认动画是从下往上显示视图,但是我希望它从右到左(飞入)进行动画处理,是否可以更改默认动画类型以及如何更改? Thanks. 谢谢。

[self presentModalViewController:navController animated:animated];

You can disable the slide-up animation like this: 您可以像这样禁用上拉动画:

[self presentModalViewController:navController animated:NO];

Then you can provide your own animation code: 然后,您可以提供自己的动画代码:

navController.view.frame = CGRectMake(320, 0, navController.view.frame.size.width, navController.view.frame.size.height);

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
navController.view.frame = CGRectMake(0, 0, navController.view.frame.size.width, navController.view.frame.size.height);
[UIView commitAnimations];

This example gives you the "Fly-in" from right with a smooth speed-curve. 本示例从右侧向您提供“飞入”,并具有平滑的速度曲线。

Another way is using the built in slide-in from right with navigationcontroller: 另一种方法是从右边使用带有导航控制器的内置幻灯片:

[self.navigationController pushViewController:navController animated:YES];

In this one, your top-viewcontroller needs to be a UINavigationController and it's rootcontroller needs to be your viewcontroller. 在这一步中,您的top-viewcontroller必须是UINavigationController,而rootcontroller必须是您的viewcontroller。 Then you can push other viewcontrollers. 然后,您可以推送其他视图控制器。

I have done this and its working for me try ths: 我已经做到了,它的工作对我来说尝试:

[UIView beginAnimations:nil context:nil];
            [UIView setAnimationDuration:0.6];
            [UIView setAnimationDelegate:self];
            [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.View2.superview cache:YES];
            [self.View2 removeFromSuperview];   
            [self performSelector:@selector(replaceViews2) withObject:nil afterDelay:0.6];
            [UIView commitAnimations];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM