0
我想縮小一個圓形的CAShapeLayer,但使用關鍵路徑「路徑」似乎沒有工作。CAShapeLayer路徑動畫 - 縮小圓圈
CGPathRef startPath = [UIBezierPath bezierPathWithOvalInRect:startRect].CGPath;
CGPathRef endPath = [UIBezierPath bezierPathWithOvalInRect:CGRectInset(startRect, 15, 15)].CGPath;
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"path"];
animation.duration = 1.0;
animation.fromValue = (__bridge id)startPath;
animation.toValue = (__bridge id)endPath;
animation.autoreverses = YES;
animation.repeatCount = CGFLOAT_MAX;
animation.timingFunction = [CAMediaTimingFunction functionWithControlPoints:0.6 :0.3 :0.8 :0.45];
//circleLayer is a CAShapeLayer
[self.circleLayer addAnimation:animation forKey:@"pathAnimation"];
我想我一定是誤解有關路徑動畫是如何工作的,因爲幾乎相同的代碼似乎很好地工作,如果我嘗試動畫,也就是說,不透明度或變換。
任何想法?
在我的頭腦中,我無法發現哪裏出了問題。我已經能夠獲得[非常類似的代碼](http://stackoverflow.com/a/18683845/608157)以前的工作。那麼,你能否證實這兩條路徑是合理的並且工作正常(主要是驗證startRect足夠大以便插入)。您可以通過簡單地將endPath分配給圓形圖層並驗證它是否有效(不使用動畫)來測試這一點。 –
什麼是'startRect'?如果它小於30x30,則插入時它將爲CGRectZero,因此'endPath'可能未定義。因爲除此之外,一切看起來都很完美。 – Cyrille