问题描述
我有一个 NSCollectionView
列出了来自Core Data源的项目。每个项目都有一个按钮,触发时该按钮会向下滑动动作视图。当此视图向下滑动时,集合视图将缩小,以使两个视图在相同的窗口空间中彼此重叠。
I have an NSCollectionView
that lists items from a Core Data source. Each item has a button that when fired slides down an action view. When this view slides down, the collection view shrinks so that both views fit on top of each other in the same window space.
为了提供良好的用户体验,我希望 NSCollectionViewItem
使操作完全可见。我有它的框架-我是从 -frameForItemAtIndex:
获得的。
To provide a good user experience I want the NSCollectionViewItem
that fired the action to be completely visible. I have it's frame - which I got from -frameForItemAtIndex:
.
如何-使用 NSRect框架
变量和我的 scrollView
出口-检查框架
是否在 scrollView
,如果不是,则滚动 scrollView
以便滚动显示?
How can I - using the NSRect frame
variable and my scrollView
outlet - check if frame
is visible in the scrollView
and, if it isn't, scroll scrollView
so that it is?
推荐答案
您应该可以执行以下操作:
You should be able to do something like this:
NSRect selectionRect = [self.collectionView frameForItemAtIndex:[[self.collectionView selectionIndexes] firstIndex]];
[self.collectionView scrollRectToVisible:selectionRect];
请注意,您发送的是 scrollRectToVisible:
到collectionView,而不是scrollView。如果selectionRect已经可见,则该调用将不执行任何操作。
Note that you're sending scrollRectToVisible:
to the collectionView, not to the scrollView. If the selectionRect is already visible, the call won't do anything.
这篇关于NSScrollView:确保框架可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!