我有一个NSTableView,我想知道用户何时滚动到底部,所以我可以执行一个动作.不太清楚如何去做?
-(void)tableViewDidScroll:(CPNotification) notification { var scrollView = [notification object]; var currentPosition = CGRectGetMaxY([scrollView visibleRect]); var tableViewHeight = [messagesTableView bounds].size.height - 100; //console.log("TableView Height: " + tableViewHeight); //console.log("Current Position: " + currentPosition); if (currentPosition > tableViewHeight - 100) { console.log("we're at the bottom!"); } }
解决方法
您可以从表的-enclosingScrollView的-contentView中添加自己作为观察者(在NSNotificationCenter意义上,而不是KVO / Bindings意义上)NSViewBoundsDidChangeNotification,并根据可见矩形进行必要的反应.
更新
在某个地方做这个(也许是-awakeFromNib):
// Configure the scroll view to send frame change notifications id clipView = [[tableView enclosingScrollView] contentView]; [[NSNotificationCenter defaultCenter] addobserver:self selector:@selector(myBoundsChangeNotificationHandler:) name:NSViewBoundsDidChangeNotification object:clipView];
把它放在有用的地方:
- (void)myBoundsChangeNotificationHandler:(NSNotification *)aNotification { if ([aNotification object] == [[tableView enclosingScrollView] contentView]) [self doSomethingInterestingIfDocumentVisibleRectSatisfiesMe]; }
基本上你想要检查滚动视图的-documentVisibleRect,看看底部几个像素是否可见.请记住使用翻转坐标系统来考虑视图的可能性 – “翻转视图” – 在Views Programming Guide中介绍.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。