同步两个NSScrollView [英] synchronize two NSScrollView

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

问题描述

我阅读了文档同步滚动视图,并且与文档完全一样,但是有一个问题.

I read the document Synchronizing Scroll Views, and did exactly as the document, but there is an isssue.

我想同步NSTableView和NSTextView.首先让NSTableView监视NSTextView,当我滚动TextView时一切正常,但是当我尝试滚动TableView时,我发现TableView首先会跳到另一个地方(可能向后几行),然后继续从那个地方滚动

I want to synchronize a NSTableView and a NSTextView. first let NSTableView monitor NSTextView, and everything is ok when I scroll the TextView, but when I try to scroll TableView, I found that the TableView will jump to another place(maybe backward several rows) at first, then continue to scroll from that place.

即使我让TextView监视TableView之后,此问题仍然存在.

This issue still exists even after I let TextView monitor TableView.

有人知道出什么问题吗?我不能同步TableView和TextView吗?

anyone know what's the problem? can't I synchronize a TableView and a TextView?

好的,现在我发现TableView将返回自上次滚动以来的位置.例如,TableView的第一行是第10行,然后我滚动TextView,现在TableView的第一行是第20行,如果再次滚动TableView,TableView将首先回到第10行,然后开始滚动.

Edited: OK, now I found that the TableView will go back to the place since last scrolling. for example, TableView's top row is 10th row, then I scroll TextView, now TableView's top row is 20th row, and if I scroll TableView again, the TableView will go back to 10th row first, then start to scroll.

推荐答案

我在解决非常相似的情况(在Lion上)时遇到了这个确切的问题.我注意到只有在隐藏滚动条时才会发生这种情况-但我验证了它们仍然存在于笔尖中,并且仍正确地实例化.

I just ran into this exact problem while troubleshooting a very similar situation (on Lion). I noticed that this only occurs when the scrollers are hidden -- but I verified that they still exist in the nib, and are still instantiated correctly.

我什至确定要呼叫-[NSScrollView reflectScrolledClipView:],但这没什么不同.看来这似乎是NSScrollView中的错误.

I even made sure to call -[NSScrollView reflectScrolledClipView:], but it didn't make a difference. It really seems like this is a bug in NSScrollView.

无论如何,我可以通过创建自定义滚动条类来解决此问题.我要做的就是重写以下类方法:

Anyway, I was able to work around the issue by creating a custom scroller class. All I had to do was override the following class methods:

+ (BOOL)isCompatibleWithOverlayScrollers
{
    // Let this scroller sit on top of the content view, rather than next to it.
    return YES;
}

- (void)setHidden:(BOOL)flag
{
    // Ugly hack: make sure we are always hidden.
    [super setHidden:YES];
}

然后,我允许滚动条在Interface Builder中可见".但是,由于它们隐藏了自己,因此它们不会出现在屏幕上,并且用户无法单击它们.令人惊讶的是,IB设置和hidden属性不等效,但是从行为上看,它们显然不相同.

Then, I allowed the scrollers to be "visible" in Interface Builder. Since they hide themselves, however, they do no appear onscreen and they can't be clicked by the user. It's surprising that the IB setting and the hidden property are not equivalent, but it seems clear from the behavior that they are not.

这不是最佳解决方案,但这是(到目前为止)我想出的最简单的解决方法.

This isn't the best solution, but it's the simplest workaround I've come up with (so far).

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

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