Created
January 4, 2012 05:37
-
-
Save kgn/1558664 to your computer and use it in GitHub Desktop.
Animated NSTableView Scrolling
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Thanks to CuriousKea for getting this started! | |
// http://stackoverflow.com/a/8480325/239380 | |
- (void)scrollRowToVisible:(NSInteger)rowIndex animate:(BOOL)animate{ | |
if(animate){ | |
NSRect rowRect = [self rectOfRow:rowIndex]; | |
NSPoint scrollOrigin = rowRect.origin; | |
NSClipView *clipView = (NSClipView *)[self superview]; | |
scrollOrigin.y += MAX(0, round((NSHeight(rowRect)-NSHeight(clipView.frame))*0.5f)); | |
NSScrollView *scrollView = (NSScrollView *)[clipView superview]; | |
if([scrollView respondsToSelector:@selector(flashScrollers)]){ | |
[scrollView flashScrollers]; | |
} | |
[[clipView animator] setBoundsOrigin:scrollOrigin]; | |
}else{ | |
[self scrollRowToVisible:rowIndex]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Swift 5.3 version