我在我的UIView的drawRect方法中繪製了一個路徑。在某些情況下,路徑將消失,並且我想對此進行動畫處理 - 讓我們將其稱爲「未繪製」路徑。將drawRect和KeyPathAnimation結合起來以解開未閃爍
對於動畫,我創建一個CAShapeLayer,給它myPath,然後設置一個CABasicAnimation(animationWithKeyPath:@「strokeEnd」)。
我的問題是如何從drawRect中繪製的內容切換到動畫。我必須從drawRect中繪製myPath並調用setNeedsDisplay - 否則動畫將被drawRect繪製的路徑隱藏。
- (void)animationDidStart:(CAAnimation *)theAnimation
{
myPath = nil;
[self setNeedsDisplay];
}
可是這樣一來我看我的路徑,然後快速閃爍,沒有路徑,則路徑是通過CoreAnimation再次呈現,是很好的未被使用。
我能更好地避免閃爍嗎?
背景 這是我如何設置動畫:
- (void) startAnimation
{
pathLayer.path = myPath.CGPath;
pathLayer.hidden = false;
CABasicAnimation *pathAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
pathAnimation.duration = 1;
pathAnimation.fromValue = [NSNumber numberWithFloat:1.0f];
pathAnimation.toValue = [NSNumber numberWithFloat:0.0f];
pathAnimation.fillMode = kCAFillModeForwards;
pathAnimation.removedOnCompletion = NO;
pathAnimation.delegate = self;
[pathLayer addAnimation:pathAnimation forKey:@"strokeEnd"];
}
你如何設置你的基本的動畫? – 2013-03-13 15:14:36
爲問題添加了動畫設置代碼。 – Miriam 2013-03-13 15:25:54
'kCAFillModeBoth'會爲你解決閃爍問題嗎? – 2013-03-13 15:49:59