谁知道将NSScrollView滚动到顶部的正确方法?我正在寻找一个与UIView的scrollToTop方法等效的方法。
这就是我到目前为止所拥有的,但它并不是在所有情况下都是正确的
[self.contentView scrollToPoint:NSMakePoint(0, MAX(contentView.frameHeight, ((NSView*)self.documentView).frameHeight))];发布于 2012-08-16 11:16:11
终于想明白了。就像一种护身符!
if ([self hasVerticalScroller]) {
self.verticalScroller.floatValue = 0;
}
NSPoint newOrigin = NSMakePoint(0, NSMaxY(((NSView*)self.documentView).frame) - self.boundsHeight);
[self.contentView scrollToPoint:newOrigin];发布于 2017-03-26 19:31:28
针对Swift 5进行了更新
如果您的文档视图被翻转:
scrollView.documentView?.scroll(.zero)否则:
if let documentView = scrollView.documentView {
documentView.scroll(NSPoint(x: 0, y: documentView.bounds.size.height))
}发布于 2015-08-07 19:14:53
这也可以很好地工作。设置NSScrollView的documentView的滚动点
NSPoint pt = NSMakePoint(0.0, [[self.scrollView documentView]
bounds].size.height);
[self.scrollView.documentView scrollPoint:pt];https://stackoverflow.com/questions/11975434
复制相似问题