2015-05-31 86 views
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魔力?

+0

據我所知,您可以使用KVO – Andy

回答

0

我找到了解決辦法,但有興趣的人士,你可以用下面的方法不與CALayar東西干擾:

- (void) didChangeValueForKey: (NSString*)aKey (void) didChangeValueForKey: (NSString*)aKey 
{ 
    // Update dependent properties 
}