NSScrollView scrollToTop

只谈情不闲聊 提交于 2019-12-04 05:54:22

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))
}

Finally figured it out. Works like a charm!

if ([self hasVerticalScroller]) {
    self.verticalScroller.floatValue = 0;
}

NSPoint newOrigin = NSMakePoint(0, NSMaxY(((NSView*)self.documentView).frame) - self.boundsHeight);
[self.contentView scrollToPoint:newOrigin];

This also works fine. Set scroll point of documentView of NSScrollView

NSPoint pt = NSMakePoint(0.0, [[self.scrollView documentView]
                               bounds].size.height);
[self.scrollView.documentView scrollPoint:pt];

The previous solutions scroll to the bottom when translating to Swift for Mac OS. The y coordinate direction is flipped on Mac OS and iOS.

Swift 3 Solution for Mac OS:

scrollView.documentView?.scroll(NSPoint.zero)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!