NSScrollView scrollToTop [英] NSScrollView scrollToTop

查看:52
本文介绍了NSScrollView scrollToTop的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道将 NSScrollView 滚动到顶部的正确方法吗?我正在寻找与 UIView 的 scrollToTop 方法等效的方法.

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, but its not quite right under all situations

[self.contentView scrollToPoint:NSMakePoint(0, MAX(contentView.frameHeight, ((NSView*)self.documentView).frameHeight))];

推荐答案

终于想通了.就像魅力一样!

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];

这篇关于NSScrollView scrollToTop的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆