Advertisement
Guest User

Untitled

a guest
Dec 18th, 2012
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @implementation AnimatableSplitView
  2.  
  3. - (id)initWithFrame:(NSRect)frame
  4. {
  5.     self = [super initWithFrame:frame];
  6.     if (self) {
  7.         // Initialization code here.
  8.     }
  9.    
  10.     return self;
  11. }
  12.  
  13. - (CGFloat)positionForDividerAtIndex:(NSInteger)idx
  14. {
  15.     NSRect frame = [[[self subviews] objectAtIndex:idx] frame];
  16.     if (self.isVertical) {
  17.         return NSMaxX(frame) + ([self dividerThickness] * idx);
  18.     }
  19.     else {
  20.         return NSMaxY(frame) + ([self dividerThickness] * idx);
  21.     }
  22. }
  23.  
  24. - (void)setPosition:(CGFloat)position ofDividerAtIndex:(NSInteger)dividerIndex animate:(BOOL)animate
  25. {
  26.     if (!animate) {
  27.         [super setPosition:position ofDividerAtIndex:dividerIndex];
  28.     }
  29.     else {
  30.         [[self animator] setValue:[NSNumber numberWithFloat:position] forKey:[NSString stringWithFormat:@"dividerPosition%li", dividerIndex, nil]];
  31.     }
  32. }
  33.  
  34. - (BOOL) _tryParsingDividerPositionIndex:(NSInteger*) anInteger fromKey:(NSString*) key
  35. {
  36.     *anInteger = 0;
  37.     return YES;
  38. }
  39.  
  40. - (id)animationForKey:(NSString *)key
  41. {
  42.     id animation = [super animationForKey:key];
  43.     NSInteger idx;
  44.     if (animation == nil && [self _tryParsingDividerPositionIndex:&idx fromKey:key]) {
  45.         animation = [super animationForKey:@"dividerPosition"];
  46.     }
  47.    
  48.     return animation;
  49. }
  50.  
  51. - (id)valueForUndefinedKey:(NSString *)key
  52. {
  53.     NSInteger idx;
  54.     if ([self _tryParsingDividerPositionIndex:&idx fromKey:key]) {
  55.         CGFloat position = [self positionForDividerAtIndex:idx];
  56.         return [NSNumber numberWithFloat:position];
  57.     }
  58.    
  59.     return nil;
  60. }
  61.  
  62. - (void)setValue:(id)value forUndefinedKey:(NSString *)key
  63. {
  64.     NSInteger idx;
  65.     if ([value isKindOfClass:[NSNumber class]] && [self _tryParsingDividerPositionIndex:&idx fromKey:key]) {
  66.         [super setPosition:[value floatValue] ofDividerAtIndex:idx];
  67.     }
  68. }
  69.  
  70. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement