2010-06-11 40 views
1

所以,我已經搜索了很多這個,似乎無法找到解決方案。UIView動畫將不會運行轉換

此代碼:

CGContextRef context = UIGraphicsGetCurrentContext(); 
[UIView beginAnimations:nil context:context]; 
[UIView setAnimationDuration:5]; 
[c setCenter:CGPointMake(200, 200)]; 
[UIView commitAnimations]; 

此代碼不:

CGContextRef context = UIGraphicsGetCurrentContext(); 
[UIView beginAnimations:nil context:context]; 
[UIView setAnimationBeginsFromCurrentState:YES]; 
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:c cache:YES]; 
[UIView setAnimationDuration:5]; 
[c exchangeSubviewAtIndex:0 withSubviewAtIndex:1]; 
[UIView commitAnimations]; 

我知道調用exchangeSubViewAtIndex工作,因爲如果我從動畫塊它起到預期中刪除。

任何人都有任何洞察力,爲什麼這個過渡不會運行?我需要導入的東西?

+0

「context」參數供動畫回調(setAnimationDelegate/setAnimationWillStartSelector/setAnimationDidStopSelector)使用。你不需要它。將其設置爲NULL。 – 2010-06-11 20:23:13

回答

1

我會引用蘋果(再次)在這裏:

如果你想有一個過渡例如在改變視圖的外觀,從一個視圖翻轉到另一臺則使用容器視圖, UIView的一個實例,如下所示:

  1. 開始一個動畫塊。
  2. 設置容器視圖上的轉換。
  3. 從容器視圖中刪除子視圖。
  4. 將新的子視圖添加到容器視圖。
  5. 提交動畫塊。

那麼你可能想使用removeFromSuperview & addSubView:,而不是如果你使用預定義的過渡交換兩個子視圖。

+0

是的,這是我遵循的模式。我從刪除和添加中獲得相同的結果,而不是交換。 – derrickp 2010-06-14 15:31:21