2010-04-14 47 views
3

我有一個CALayer菜單,它將在屏幕上滑動到給定點。我想要菜單稍微超過點的效果,然後在點前點,然後落在點上。我可以通過應用轉換來移動菜單,但我希望能夠使這種彈跳效果起作用。我正在研究CAKeyframeAnimation,但我在查找示例/教程時遇到了問題。我看過CA編程指南,但還沒有真正找到任何東西。任何鏈接或幫助將是偉大的。謝謝。CAKeyframeAnimation - 示例

+1

檢查http://stackoverflow.com/questions/5161465/how-to-create-custom-easing-function-with-core-animation。那裏的第一個答案可能會給你一些想法。 – 2011-03-06 13:41:49

+0

簽出這個框架我建立了一些邪惡的東西:)應該是一個相當不錯的抽象,因爲它在引擎蓋下做了很多事情https://github.com/AntonTheDev/FlightAnimator – AntonTheDev 2016-06-23 10:12:56

回答

4

前一段時間我發佈了some code,它只是做你正在尋找的東西。基本上,您需要生成自己的CGPathRef,其中包含要讓圖層擊中的所有點,並將該路徑用於CAKeyframeAnimationpath屬性。代碼將如下所示:

CGPoint path[3] = { 
    FTAnimationOutOfViewCenterPoint(enclosingView.bounds, view.frame, view.center, direction), 
    [self overshootPointFor:view.center withDirection:direction threshold:(overshootThreshold_ * 1.15)], 
    view.center 
}; 

CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"position"]; 
CGMutablePathRef thePath = CGPathCreateMutable(); 
CGPathAddLines(thePath, NULL, path, 3); 
animation.path = thePath; 
CGPathRelease(thePath); 

整個方法是here