2012-02-25 57 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