亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

有沒有什么辦法是可以指定路徑做動畫的?

有沒有什么辦法是可以指定路徑做動畫的?

iOS
GCT1015 2023-04-16 21:17:11
之前做動畫一直用這種方法[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];

代碼塊中,你可以對一個或多個視圖同時添加多個動畫效果(如改變其顏色、大小等),來實現更為復雜的動畫


查看完整回答
反對 回復 2023-04-20
?
小怪獸愛吃肉

TA貢獻1852條經驗 獲得超1個贊

Core Animation。

查看完整回答
反對 回復 2023-04-20
  • 2 回答
  • 0 關注
  • 167 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號