NSCollectionView 与部分 - 就像在 iPhoto 中一样
我想构建一个类似于 iPhoto '11 中的 NSCollectionView 。我想将几张图片分组到部分中,并创建一个部分标题。特定节的节标题始终可见,直到该节的最后一个元素可见。你可以看看图片就明白我的意思了。
编辑:我应该补充一点,内容不是图像。
提前致谢
I'd like to build a NSCollectionView similar to the one in iPhoto '11. I want to group several pictures in section, and create a section header as well. The section header of a specific section is always visible until the last element of that section is visible. You can take a look at the picture to see what I mean.
EDIT: I should add that the contents are not images.
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可能需要直接考虑使用 CALayers。 NSCollectionView 的大部分魔力来自 CoreAnimation IIRC,看起来您可能必须复制其中的一些。或者,您可以尝试使用嵌套集合视图 - 一个包含组,然后每个组包含单个项目的另一个集合视图。
无论哪种方式,您的视图/图层层次结构都将是相同的。您将拥有一个只有一列的顶级容器(因为组延伸到整个宽度),然后其中的每个项目将具有任意数量的列,具体取决于项目宽度。即您的“组”集合视图项目将拉伸至填充宽度,但这些组中的各个项目不会。
如果您选择使用原始
CALayer
方法,那么您需要查看CAConstraintLayoutManager
。这就是 NSCollectionView 内部的魔力所在。开始寻找这方面信息的好地方是 Pragmatic Programmers 出品的 Bill Dudney 的 CoreAnimation 书籍。比尔现在是苹果的官方平台布道者,所以我认为可以肯定地说他知道他在那里谈论的是什么。总的来说,我建议首先使用嵌套的 NSCollectionView 方法,并且仅在性能似乎缺乏或者某些东西无法正常工作时才考虑使用原始 CoreAnimation。使用
NSCollectionView
可以让您保留所有当前的NSView
状态,因此工作量会减少。如果结果没问题,那么您就回家了。干燥。如果没有,您还可以尝试其他方法,并根据自己的喜好进行调整。You're probably going to have to look at using CALayers directly.
NSCollectionView
gets most of its magic from CoreAnimation IIRC, and it looks like you might have to duplicate some of that. Alternatively you could try using nested collection views— one containing groups, then each group contains another collection view of individual items.Either way, your view/layer hierarchy is going to be the same. You'll have a top-level container which has only one column (since groups stretch across the entire width), then each item within that will have any number of columns, based on the item width. i.e. your 'group' collection view items will stretch to fill width, but your individual items within those groups won't.
If you choose to use the raw
CALayer
approach, then you'll want to look atCAConstraintLayoutManager
. This is what provides the magic insideNSCollectionView
. A good place to start looking for information on this is Bill Dudney's CoreAnimation book from Pragmatic Programmers. Bill's now the official platform evangelist for Apple, so I think it's safe to say he knows what he's talking about in there.Overall, I'd suggest using a nested
NSCollectionView
approach to start with, and look at dropping down to raw CoreAnimation only if performance seems to be lacking, or if you have issues getting some stuff to work. UsingNSCollectionView
lets you keep all your currentNSView
-ness in place, so it will be less work. If it turns out ok, then you're home & dry. If not, you've got something else to try which you can tweak to your heart's content.这是一个类似的示例:
检查一下:https://developer.apple.com/library/mac/samplecode/TableViewPlayground/Introduction/Intro.html #//apple_ref/doc/uid/DTS40010727
Here is a similar sample:
Check this: https://developer.apple.com/library/mac/samplecode/TableViewPlayground/Introduction/Intro.html#//apple_ref/doc/uid/DTS40010727