NSScrollView 中的 NSTableView 在拖动时不会自动滚动 [英] NSTableView in NSScrollView doesn't autoscroll when dragging
问题描述
我目前正在我的 OS X 应用程序的表格视图中实现拖放重新排列.虽然正常滚动工作正常,但拖动时自动滚动完全损坏.
I'm currently implementing drag and drop rearranging in a table view in my OS X app. While normal scrolling works fine, autoscroll while dragging it totally broken.
如果我抓住一个单元格并开始拖动,自动滚动只会告诉表格滚动到顶部.如果我在拖动过程中使用触控板手动滚动,表格会不断弹出到顶部.如果我拖动顶部的单元格之一,当拖动到底部附近时表格不会自动向下滚动.
If I grab a cell and start dragging, autoscroll just tells the table to scroll to the top. If I manually scroll using the trackpad during dragging the table continually pops to the top. If I drag one of the top cells, the table will not autoscroll down when dragging near the bottom.
我继承了 NSScrollView 并覆盖了 scrollClipView
方法.我看到它被一些内部自动滚动方法调用,坐标为 (0, 0).
I subclassed NSScrollView and overrode the scrollClipView
method. I see that it's being called by some internal autoscroll method with the coordinates of (0, 0).
由于我看不到那个内部方法在做什么,而且 Goggle 和 SO 什么也没有出现,我有点卡住了.
Since I can't see what that internal method is doing, and Goggle and SO are turning up nothing, I'm a bit stuck.
以前有人遇到过这个问题吗?根据过去的经验,我觉得它与 AutoLayout 相关,但我不知道是什么.或者可能是完全不相关的东西.
Has anyone run into this issue before? From past experiences, I have the feeling it's something AutoLayout related, but I have no idea what. Or maybe it's something completely unrelated.
关于如何进一步排除故障的任何想法?
Any ideas on how to further troubleshoot?
推荐答案
我遇到了同样的问题.就我而言,问题在于我在 Interface Builder 中将 NSTableCellView
的高度设置为 10,000,这样就不会在实际行下方的空行中显示水平分隔符.
I ran into the same issue. In my case, the problem was that I set the height of the NSTableCellView
to 10,000 in Interface Builder so that the horizontal separators wouldn’t be displayed for empty rows below the actual rows.
但是,我的 NSTableCellViews
在运行时加载的实际高度是 43 像素.
However, the actual height of my NSTableCellViews
loaded at run time was 43px.
因此,当我开始拖动单元格以对其重新排序时,NSScrollView
尝试一次滚动 10,000 个像素,而不是一次滚动 43 个像素.
So as soon as I started dragging a cell to re-order it, the NSScrollView
was trying to scroll 10,000 pixels at a time instead of 43 at a time.
这似乎是一个错误,因为我的 NSOutlineView
子类确实实现了以下方法来动态设置每行的高度.
This seems like a bug, because my NSOutlineView
subclass does implement the following method to dynamically set the height of each row.
func outlineView(_ outlineView: NSOutlineView, heightOfRowByItem item: Any) -> CGFloat
显然该方法在拖放操作期间被自动滚动机制忽略,并且仅使用在Interface Builder中设置的值.
Apparently that method is ignored by the autoscroll mechanism during drag and drop operations, and only the value set in Interface Builder is used.
所以我只是在 Interface Builder 中将虚拟 NSTableCellView
的高度更改为 43px,然后我将忍受为空行显示的水平分隔符.
So I just changed the height of the dummy NSTableCellView
to 43px in Interface Builder, and I’ll just live with the horizontal separators being displayed for empty rows.
这篇关于NSScrollView 中的 NSTableView 在拖动时不会自动滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!