NSScrollView scrollToTop

后端 未结 4 1529
一向
一向 2021-02-14 16:55

Does anyone know the correct way to scroll the NSScrollView to the top? I was looking for an equivalent to the UIView\'s scrollToTop method.

This is what I have so far,

4条回答
  •  后悔当初
    2021-02-14 17:49

    Updated for Swift 5:

    If your document view is flipped:

    scrollView.documentView?.scroll(.zero)
    

    otherwise:

    if let documentView = scrollView.documentView {
            documentView.scroll(NSPoint(x: 0, y: documentView.bounds.size.height))
    }
    

提交回复
热议问题