2011-03-28 114 views
19

我找到了一些這樣的代碼:我怎樣才能知道值CABasicAnimation的keyPath

CABasicAnimation *anim = [CABasicAnimation animation]; 
anim.keyPath = @"transform.scale"; 
anim.fromValue = [NSNumber numberWithFloat:1.0]; 
anim.toValue = [NSNumber numberWithFloat:0]; 
anim.removedOnCompletion = NO; 
anim.fillMode = kCAFillModeBoth; 
anim.delegate = self; 
[self.view.layer addAnimation:anim forKey:@"scaleOut"]; 

anim.keyPath = @"transform.rotation.x"; 

據我所知,是的keyPath鏈式方法調用。 CALayer的「transform.scale」是aLayer.transform.scale。 「變換」是CALayer的一個屬性,「尺度」是變換的「屬性」。但CALayer中的屬性轉換是CATransform3D。

CATransform3D中沒有名爲「scale」或「rotation」的屬性。

我的問題是: keyPath如何識別「縮放」和「旋轉」?

回答

23

核心動畫擴展KVC以支持層的某些結構類型屬性的字段(或僞字段)的直接尋址。該功能在Core Animation Extensions To Key-Value Coding中描述。

+5

例如,'scale.xy'不在該列表中。所以它不完整。我應該在哪裏找到所有關鍵路徑或缺失的路徑? – 2016-03-23 12:22:11

2

我不確定,但是我找到了一個可能有幫助的解決方案。

斯威夫特: 而不是寫你可以使用這個字符串的:

let shadowAnimation = CABasicAnimation(keyPath: #keyPath(CALayer.shadowRadius)) 

當你鍵入的CALayer。 < - 自動完成應該爲您提供可用的keyPaths。

我希望這會有所幫助。