CATransition如何工作? [英] how does the CATransition work?
问题描述
我有两个视图,一个是aView,另一个是bView,aView上有一个按钮,我单击该按钮,我将跳到bView,请查看代码
i have two views,one is aView,another is bView, there is a button on aView,i click the button ,i will jump to bView,please see the code
-(IBAction)jump2b:(id)sender{
CATransition *animation = [CATransition animation];
animation.delegate = self;
animation.duration = 0.25f;
animation.timingFunction = UIViewAnimationCurveEaseInOut;
animation.fillMode = kCAFillModeForwards;
animation.removedOnCompletion = NO;
animation.type = kCATransitionPush;
animation.subtype = kCATransitionFromTop;
[bView.view.layer addAnimation:animation forKey:@"animation"];
}
它不能很好地工作,它可以跳跃,所以我该怎么办?谢谢
it can not work well,it can jump,so what can i do?thanks
推荐答案
您忘了实际在视图末尾添加视图...
You forgot to actually add the view at the end...
-(IBAction)jump2b:(id)sender{
CATransition *animation = [CATransition animation];
animation.delegate = self;
animation.duration = 0.25f;
animation.timingFunction = UIViewAnimationCurveEaseInOut;
animation.fillMode = kCAFillModeForwards;
animation.removedOnCompletion = NO;
animation.type = kCATransitionPush;
animation.subtype = kCATransitionFromTop;
[bView.view.layer addAnimation:animation forKey:@"animation"];
//add bView to current view
[self.view addSubview:bView];
}
为什么没有使用UIView动画块?自iOS 4以来,这是动画的推荐方法.使用UIView的transitionFromView:toView:duration:options:completion:应该适合您...
Is there reason why you're not using UIView animation blocks? It's the recommended method for animations since iOS 4. Using UIView's transitionFromView:toView:duration:options:completion: should work for you...
[UIView transitionFromView:aView
toView:bView
duration:0.25
options: (UIViewAnimationCurveEaseInOut | UIViewAnimationOptionTransitionCurlUp)
completion:nil];
我以UIViewAnimationOptionTransitionCurlUp作为过渡选项的示例,但是您可以选择任何UIViewAnimationOption.
I used UIViewAnimationOptionTransitionCurlUp as an example for the transition option, but you can choose any UIViewAnimationOption.
这篇关于CATransition如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!