之前做動畫一直用這種方法[UIView beginAnimations:@"animation" context:NULL];
[UIView setAnimationDuration:0.5f];// 新位置[UIView commitAnimations];但是解決不了View需要轉向的問題。我現在需要讓這個動畫過程中,View有一個抖動的效果,這個實現不了,除非我用延遲,做兩次動畫,感覺這樣很惡心。
2 回答

Helenr
TA貢獻1780條經驗 獲得超4個贊
用Core Animation,可以指定動畫路徑。
下面例子實現一個物體下落再彈起的動畫
[CATransaction begin]; [CATransaction setValue:[NSNumber numberWithFloat:ANIMATION_DURATION] forKey:kCATransactionAnimationDuration]; CAKeyframeAnimation *positionAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"]; CGMutablePathRef positionPath = CGPathCreateMutable(); CGPathMoveToPoint(positionPath, NULL, [theView layer].position.x, [theView layer].position.y); CGPathAddQuadCurveToPoint(positionPath, NULL, [theView layer].position.x, - [theView layer].position.y, [theView layer].position.x, [theView layer].position.y); CGPathAddQuadCurveToPoint(positionPath, NULL, [theView layer].position.x, - [theView layer].position.y * 1.5, [theView layer].position.x, [theView layer].position.y); CGPathAddQuadCurveToPoint(positionPath, NULL, [theView layer].position.x, - [theView layer].position.y * 1.25, [theView layer].position.x, [theView layer].position.y); positionAnimation.path = positionPath; positionAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]; [[theView layer] addAnimation:positionAnimation forKey:@"positionAnimation"]; CGPathRelease(positionPath); [CATransaction commit];
當然,在
[CATransaction begin]; ... [CATransaction commit];
代碼塊中,你可以對一個或多個視圖同時添加多個動畫效果(如改變其顏色、大小等),來實現更為復雜的動畫
- 2 回答
- 0 關注
- 167 瀏覽
添加回答
舉報
0/150
提交
取消