嗨我正在使用CABasicAnimation在CAShapeLayer中設置動畫路徑。當用戶TAPP的按鈕,我叫:CABasicAnimation - 從一個動畫切換到另一個動畫。如何獲得動畫的當前值?
CABasicAnimation *expandAnimation = [CABasicAnimation animationWithKeyPath:@"path"];
expandAnimation.toValue = (id)[UIBezierPath bezierPathWithOvalInRect:CGRectMake(0,0,30,30)].CGPath;
expandAnimation.duration = 1.0;
expandAnimation.fillMode = kCAFillModeBoth;
expandAnimation.removedOnCompletion = NO;
[self.circleShape addAnimation:expandAnimation forKey:expandAnimation.keyPath];
當釋放按鈕,我動畫這樣的:
CABasicAnimation *narrowAnimation = [CABasicAnimation animationWithKeyPath:@"path"];
narrowAnimation.fromValue = (id)[UIBezierPath bezierPathWithOvalInRect:CGRectMake(0,0,30,30)].CGPath;
narrowAnimation.toValue = (id)[UIBezierPath bezierPathWithOvalInRect:CGRectMake(5, 5, 20, 20)].CGPath;
narrowAnimation.duration = .5;
narrowAnimation.fillMode = kCAFillModeBoth;
narrowAnimation.removedOnCompletion = NO;
[self.circleShape addAnimation:narrowAnimation forKey:narrowAnimation.keyPath];
有時第一動畫還是動畫,同時我開始第二個。我怎樣才能得到第一個動畫的當前狀態,所以我可以設置第二個動畫的起始值從該狀態開始?
對於使用BezierPaths的值。
你嘗試'[層removeAnimationForKey:@ 「路徑」];'做一個動畫之前? – anhtu
這不是我想的問題。當我調用第二個動畫時,第一個動畫會自動停止。我只想讓這個圈子從當前狀態開始縮小,而不是從最大尺寸縮小。 –
謝謝,我現在明白了這個問題。 – anhtu