2010-08-04 27 views
1

由於無法描述的原因,我正在編程上將我的應用程序標籤欄更改爲不同的視圖。不幸的是,這是瞬間的,我們希望當你在導航控制器上執行pushViewController時,你會得到正常的負載效應。在更改UITabBar的選定標籤時模仿「正常」視圖轉換

我非常缺乏經驗,在objc c中使用動畫,我嘗試使用一些代碼,我發現這裏的礦:

CGContextRef context = UIGraphicsGetCurrentContext(); 
[UIView beginAnimations:nil context:context]; 
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:[self view] cache:YES]; 
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; 
[UIView setAnimationDuration:2.0]; 
[[[self nav] tabBarController] setSelectedIndex:2]; 
[UIView commitAnimations]; 

這確實各種各樣的動畫,導航欄神祕地從上面看來,不完全是我想要的:)

+1

我知道這是舊的,但對於它的價值,從iOS 4.0開始,您可以使用新的UIView轉換函數。我做了一些非常相似的事情,但是在完成的動畫模塊中調用了setSelectedIndex:這個模塊效果很好。 – slycrel 2010-11-30 08:15:16

回答

0

讓動畫做你想做的事情的最簡單方法是首先將它從你想要的地方放置出來(大概在屏幕之外),然後然後啓動[UIView ...]塊,在其中設置新的幀。所以大致輪廓是:

CGRect newframe = theView.frame; 
newframe.origin.x = 320.0f; 
theView.frame = newframe; 

[UIView beginAnimations:nil context:nil]; 
      // btw the context is just your context for animation delegate callbacks! 
newframe.origin.x = 0.0f; 
theView.frame = newframe; 
[UIView commitAnimations]; 

注意,所有這些代碼是在瞬間執行,所以setSelectedIndex將立即設置,以及:因爲沒有UIView參與那裏,它不是動畫。要發佈過去的動畫,請查看其他問題。 (簡而言之:使用animationDelegate或performSelector:afterDelay :)