如何从左到右推动具有滑动效果的 ViewController?需要动画名称 [英] How to push ViewController with slide effect from left to right? Animation name required
问题描述
- 下面这个gif的动画名称是什么(从右到左)?
- 下面这个gif的补充动画的动画名称是什么(从左到右)?
注意:我不想推动转场.我想用那个动画推送一个视图.
NOTE: I don't want to push a segue. I want to push a view with that animation.
编辑 2:
当我谈论动画名称时,有些人会感到困惑.但是,这是一个有效的动画名称示例(名称为:UIViewAnimationTransitionFlipFromRight):
Some people are confused when I talk about animation names. However here is an example of an animation name that works (name is: UIViewAnimationTransitionFlipFromRight):
[UIView beginAnimations: @"Showinfo"context: nil];
[UIView setAnimationCurve: UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.75];
[self.navigationController pushViewController: view animated:NO];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.navigationController.view cache:NO];
[UIView commitAnimations];
我正在使用 push 和 pop 来调用堆栈上的操作.我相信导航控制器将导航保持在堆栈样式结构中.
I am using push and pop to recall the actions on a stack. I believe that Navigation controller keeps the navigation in a stack style structure.
我正在使用导航控制器,我喜欢使用导航栏项目返回(弹出)到上一个视图时获得的效果.从右到左的效果很好,很流畅.
I am using a Navigation controller and I like the effect that I get when I go back (pop) to the previous view using the navigation bar item. It is a nice and smooth from right to left effect.
这是一个从右到左效果的例子:
如何创建互补的从右到左的效果?换句话说,当我在视图层次结构中向下时?
How can I create the complementary a from right to left effect? In other words when I go down in the view hierarchy?
这就是我目前推送视图控制器的方式:
This is how I push the view controller at the moment:
[self.navigationController pushViewController:view animated:YES];
推荐答案
我们需要为我们的 viewController 添加 CATransition 动画.看看这个,
We need to add CATransition animation for our viewController. look at this,
add <CAAnimationDelegate> in your .h file
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle: nil];
ViewController *VC = [storyboard instantiateViewControllerWithIdentifier:@ViewController"];
CATransition *transition = [CATransition animation];
transition.duration = 0.45;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault];
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromLeft;
transition.delegate = self;
[self.navigationController.view.layer addAnimation:transition forKey:nil];
[self.navigationController pushViewController:VC animated:NO];
这篇关于如何从左到右推动具有滑动效果的 ViewController?需要动画名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!