// // KMScrollView.swift // PDF Reader Pro // // Created by Niehaoyu on 2025/1/10. // import Cocoa class KMScrollView: NSScrollView { var contentViewSize: CGSize? = nil override func draw(_ dirtyRect: NSRect) { super.draw(dirtyRect) // Drawing code here. } override func layout() { super.layout() if let value = contentViewSize { self.documentView?.frame = CGRectMake(0, 0, value.width, max(value.height, self.bounds.size.height)) } } func scrollToTop() { let rect = documentView?.bounds ?? CGRectZero documentView?.scroll(CGPoint(x: 0, y: rect.size.height)) } }