Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @implementation AnimatableSplitView
- - (id)initWithFrame:(NSRect)frame
- {
- self = [super initWithFrame:frame];
- if (self) {
- // Initialization code here.
- }
- return self;
- }
- - (CGFloat)positionForDividerAtIndex:(NSInteger)idx
- {
- NSRect frame = [[[self subviews] objectAtIndex:idx] frame];
- if (self.isVertical) {
- return NSMaxX(frame) + ([self dividerThickness] * idx);
- }
- else {
- return NSMaxY(frame) + ([self dividerThickness] * idx);
- }
- }
- - (void)setPosition:(CGFloat)position ofDividerAtIndex:(NSInteger)dividerIndex animate:(BOOL)animate
- {
- if (!animate) {
- [super setPosition:position ofDividerAtIndex:dividerIndex];
- }
- else {
- [[self animator] setValue:[NSNumber numberWithFloat:position] forKey:[NSString stringWithFormat:@"dividerPosition%li", dividerIndex, nil]];
- }
- }
- - (BOOL) _tryParsingDividerPositionIndex:(NSInteger*) anInteger fromKey:(NSString*) key
- {
- *anInteger = 0;
- return YES;
- }
- - (id)animationForKey:(NSString *)key
- {
- id animation = [super animationForKey:key];
- NSInteger idx;
- if (animation == nil && [self _tryParsingDividerPositionIndex:&idx fromKey:key]) {
- animation = [super animationForKey:@"dividerPosition"];
- }
- return animation;
- }
- - (id)valueForUndefinedKey:(NSString *)key
- {
- NSInteger idx;
- if ([self _tryParsingDividerPositionIndex:&idx fromKey:key]) {
- CGFloat position = [self positionForDividerAtIndex:idx];
- return [NSNumber numberWithFloat:position];
- }
- return nil;
- }
- - (void)setValue:(id)value forUndefinedKey:(NSString *)key
- {
- NSInteger idx;
- if ([value isKindOfClass:[NSNumber class]] && [self _tryParsingDividerPositionIndex:&idx fromKey:key]) {
- [super setPosition:[value floatValue] ofDividerAtIndex:idx];
- }
- }
- @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement