// // KMSplitView.m // SignFlow // // Created by wanjun on 2021/5/26. // #import "KMSplitView.h" #import NSString *CPDFOfficeSplitViewAnimationDidEndNotification = @"CPDFOfficeSplitViewAnimationDidEndNotification"; NSString *CPDFOfficeDisableAnimationsKey = @"CPDFOfficeDisableAnimationsKey"; @implementation KMSplitView @synthesize animating; + (id)defaultAnimationForKey:(NSString *)key { if ([key isEqualToString:@"firstSplitPosition"] || [key isEqualToString:@"secondSplitPosition"]) return [CABasicAnimation animation]; else return [super defaultAnimationForKey:key]; } - (NSColor*)dividerColor { return [NSColor whiteColor]; } - (CGFloat)firstSplitPosition { NSView *view = [[self subviews] objectAtIndex:0]; if ([self isSubviewCollapsed:view]) return [self minPossiblePositionOfDividerAtIndex:0]; else if ([self isVertical]) return NSMaxX([view frame]); else return NSMaxY([view frame]); } - (void)setFirstSplitPosition:(CGFloat)position { [self setPosition:position ofDividerAtIndex:0]; } - (CGFloat)secondSplitPosition { NSView *view = [[self subviews] objectAtIndex:1]; if ([self isSubviewCollapsed:view]) return [self minPossiblePositionOfDividerAtIndex:1]; else if ([self isVertical]) return NSMaxX([view frame]); else return NSMaxY([view frame]); } - (void)setSecondSplitPosition:(CGFloat)position { [self setPosition:position ofDividerAtIndex:1]; } - (void)setPosition:(CGFloat)position ofDividerAtIndex:(NSInteger)dividerIndex animate:(BOOL)animate { if ([[NSUserDefaults standardUserDefaults] boolForKey:CPDFOfficeDisableAnimationsKey] || dividerIndex > 1) animate = NO; if (animating) { // do nothing } else if (animate == NO) { [self setPosition:position ofDividerAtIndex:dividerIndex]; } else { animating = YES; [NSAnimationContext runAnimationGroup:^(NSAnimationContext *context){ if (dividerIndex == 0) [[self animator] setFirstSplitPosition:position]; else if (dividerIndex == 1) [[self animator] setSecondSplitPosition:position]; else [self setPosition:position ofDividerAtIndex:dividerIndex]; } completionHandler:^{ animating = NO; [[NSNotificationCenter defaultCenter] postNotificationName:CPDFOfficeSplitViewAnimationDidEndNotification object:self]; }]; } } @end