KMScrollView.swift 695 B

123456789101112131415161718192021222324252627282930313233
  1. //
  2. // KMScrollView.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by Niehaoyu on 2025/1/10.
  6. //
  7. import Cocoa
  8. class KMScrollView: NSScrollView {
  9. var contentViewSize: CGSize? = nil
  10. override func draw(_ dirtyRect: NSRect) {
  11. super.draw(dirtyRect)
  12. // Drawing code here.
  13. }
  14. override func layout() {
  15. super.layout()
  16. if let value = contentViewSize {
  17. self.documentView?.frame = CGRectMake(0, 0, value.width, max(value.height, self.bounds.size.height))
  18. }
  19. }
  20. func scrollToTop() {
  21. let rect = documentView?.bounds ?? CGRectZero
  22. documentView?.scroll(CGPoint(x: 0, y: rect.size.height))
  23. }
  24. }