CAKeyframeAnimation是否可以與路徑一起使用,而不是使用關鍵幀值 來動畫(非位置)屬性?下面是關鍵代碼:定義不透明度的CAKeyframeAnimation路徑?
CAKeyframeAnimation *theLeftGradientAnimation = [CAKeyframeAnimation animationWithKeyPath:@"opacity"];
theLeftGradientAnimation.removedOnCompletion = NO;
theLeftGradientAnimation.fillMode = kCAFillModeForwards;
theLeftGradientAnimation.duration = (isToClose ? self.fromDuration : self.toDuration);
//test with a linear monotonic path to define the opacity function response
UIBezierPath *shadePath = [UIBezierPath bezierPath];
[shadePath moveToPoint:CGPointMake(0.0f, 0.0)]; //ASSUME coords are: x->t y->alpha(t)
[shadePath addLineToPoint:CGPointMake(1.0f, 1.0f)]; //ASSUME time normalized to duration
[shadePath closePath];
theLeftGradientAnimation.path = shadePath.CGPath;
不過,這並沒有相當工作properly-透明度不順利動畫,雖然根據道路的變化不是單調或精確(假設路徑是「規範化」從(0.0,0.0)到(1.0,1.0)就像一個緩動函數)。請注意,我是而不是動畫位置或移動路徑上的圖層,但希望將其用於任何動畫屬性。
文檔中存在一些不明確的地方,表明可以使用路徑來有效地定義動畫時間與動畫屬性的傳遞函數(從而替代將基於以下內容創建的關鍵幀值的數組):該傳遞函數)。同樣在iOS 6關於「關鍵幀計時和起搏擴展」的文檔中也試圖闡明路徑與值的使用,但仍然不明確。
如果指定路徑屬性按假定工作(嘗試不用運氣),則timingFunction的使用將是多餘的。請注意,測試代碼僅用於確定這可能如何工作的目的來指定線性單調函數。最終,我想用這種方式使用複雜的非線性函數來動畫屬性(無法使用functionWithControlPoints ::: :)進行自定義。 – Rich
我對這個意圖不明確表示歉意。 使用timingFunctions(複數)也是多餘的,因爲它的可選用途在指定關鍵幀值而不是路徑時也是相關的。不幸的是,周圍缺少CAKeyframeAnimation代碼示例,更不用說知道這種用法是否有效。 – Rich
閱讀文檔,在我看來,路徑根本不包含定時組件,而只是有效地作爲均勻間隔值的列表。 CGPoint值如何轉化爲標量值,比如alpha,我不知道。如果我是你,我首先嚐試使用'values'和'keyTimes',試驗哪個'calculateMode'效果最好。重新閱讀'timingFunctions','timingFunction'(奇異)的文檔根本不能用'CAKeyframeAnimation'工作。你如何看待你的價值觀? – fzwo