NSScrollView: Make sure frame is visible

你。 提交于 2019-12-11 07:48:21

问题


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.

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:.

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?


回答1:


You should be able to do something like this:

NSRect selectionRect = [self.collectionView frameForItemAtIndex:[[self.collectionView selectionIndexes] firstIndex]];
[self.collectionView scrollRectToVisible: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.



来源:https://stackoverflow.com/questions/9143915/nsscrollview-make-sure-frame-is-visible

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!