0
我在CAGradientLayer
派生類上創建了自定義動畫屬性,該類必須更改CAGradientLayer
基類中的其他內置動畫屬性,並且想知道最佳方法是什麼。目前,我的顯示方法更新相關屬性:CALayer:更新內置動畫屬性的自定義動畫屬性
@implementation CustomGradientLayer
@dynamic myCustomProperty;
+ (BOOL) needsDisplayForKey: (NSString*)aKey
{
BOOL needsDisplay = [aKey isEqualToString: @"myCustomProperty"];
if (!needsDisplay)
{
needsDisplay = [super needsDisplayForKey: aKey];
}
return needsDisplay;
}
- (void) display
{
CGFloat myCustomProperty = [self.presentationLayer myCustomProperty];
[CATransaction begin];
[CATransaction setDisableActions: YES];
// Update dependant properties on self
[CATransaction commit];
[super display];
}
是否可以安全地更新在自定義屬性setter依賴的屬性,而不是不影響基礎CALayer
魔力?
據我所知,您可以使用KVO – Andy