2012-02-25 80 views
-3
view=[[UIView alloc]init]; 
[UIView beginAnimations:@"flipping view" context:nil]; 
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; 
[UIView setAnimationDuration:2]; 
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp 
         forView:self.view cache:YES]; 
[self.view addSubview:view.view]; 
    [UIView commitAnimations]; 

我使用这个,但我想像两个导航控制器的动画。 我正在使用两个UIViews。两个UIViews之间的动画

+0

你能告诉我为什么否决。 – 2012-02-25 07:58:16

+5

因为这不是问题。这是一个“给我一些代码而不用麻烦解释”的请求。请阅读常见问题解答:http://stackoverflow.com/faq – Cyrille 2012-02-25 10:31:39

回答

6

您需要将过渡动画应用于包含从一个子视图切换到另一个子视图的动画的父视图。

UIView* view=[[UIView alloc]init]; 
UIView* parentView = self.view.superview; 
[self.view removeFromSuperView]; 
[parentView addSubview:view]; 


CATransition *animation = [CATransition animation]; 
[animation setDelegate:self]; // set your delegate her to know when transition ended 

[animation setType:kCATransitionPush]; 
[animation setSubtype:kCATransitionFromRight]; // set direction as you need 

[animation setDuration:0.5]; 
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]]; 

[[parentView layer] addAnimation:animation forKey:@"viewPush"]; 

您可能需要进一步调整这个代码在你的类设计的情况下工作,等

+0

好的...但我不想把@“翻转视图”还有什么我可以写在这里 – 2012-02-25 09:33:25

+0

我不确定你的问题是什么。如果你想做一个从一个视图到另一个视图的过渡动画,这就是你如何做到的。 – kamprath 2012-02-25 09:37:34

+0

我想在两个uview之间切换时模仿UINavigation动画行为。 – 2012-02-25 09:40:59