知识点:
1、使某一行显示在视图的中间位置:
extension NSTableView {
func scrollRowToCenter(_ row: Int) {
guard let clipView = superview as? NSClipView, let scrollView = clipView.superview as? NSScrollView else {
assertionFailure("Unexpected NSTableView view hiearchy")
return
}
let rowRect = rect(ofRow: row)
var scrollOrigin = rowRect.origin
let tableHalfHeight = clipView.frame.height * 0.5
let rowRectHalgHeight = rowRect.height * 0.5
scrollOrigin.y = (scrollOrigin.y - tableHalfHeight) + rowRectHalgHeight
scrollView.flashScrollers()
clipView.setBoundsOrigin(scrollOrigin)
}
}