use*_*889 7 nsscrollview scrolltop
有谁知道将NSScrollView滚动到顶部的正确方法?我正在寻找UIView的scrollToTop方法的等价物.
这是我到目前为止所做的,但在所有情况下都不太正确
[self.contentView scrollToPoint:NSMakePoint(0, MAX(contentView.frameHeight, ((NSView*)self.documentView).frameHeight))];
Run Code Online (Sandbox Code Playgroud)
为Swift 5更新:
如果您的文档视图被翻转:
scrollView.documentView?.scroll(.zero)
Run Code Online (Sandbox Code Playgroud)
除此以外:
if let documentView = scrollView.documentView {
documentView.scroll(NSPoint(x: 0, y: documentView.bounds.size.height))
}
Run Code Online (Sandbox Code Playgroud)
终于想通了.奇迹般有效!
if ([self hasVerticalScroller]) {
self.verticalScroller.floatValue = 0;
}
NSPoint newOrigin = NSMakePoint(0, NSMaxY(((NSView*)self.documentView).frame) - self.boundsHeight);
[self.contentView scrollToPoint:newOrigin];
Run Code Online (Sandbox Code Playgroud)
这也很好用。设置 NSScrollView 的 documentView 滚动点
NSPoint pt = NSMakePoint(0.0, [[self.scrollView documentView]
bounds].size.height);
[self.scrollView.documentView scrollPoint:pt];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3254 次 |
| 最近记录: |