NSCollectionView与部分 - 如在iPhoto [英] NSCollectionView with sections - like in iPhoto

查看:187
本文介绍了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.

编辑:我应该补充说,内容不是图片。

I should add that the contents are not images.

>

提前感谢

推荐答案

您可能需要直接使用CALayers。 NSCollectionView 从CoreAnimation IIRC获得了大部分魔法,看起来你可能需要重复一些。或者,您可以尝试使用嵌套集合视图 - 一个包含组,然后每个组包含单个项目的另一个集合视图。

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.

如果您选择使用原始 CALayer 方法,那么您将需要查看 CAConstraintLayoutManager 。这是提供 NSCollectionView 中神奇的东西。开始寻找信息的好地方是 Bill Dudney的Pragmatic Programmers的CoreAnimation书。 Bill现在是苹果公司的官方平台传播者,所以我认为可以说他知道他在说什么。

If you choose to use the raw CALayer approach, then you'll want to look at CAConstraintLayoutManager. This is what provides the magic inside NSCollectionView. 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.

总的来说,我建议使用嵌套的 NSCollectionView 方法开始,并看看下降到原始的CoreAnimation只有当性能似乎缺乏,或者如果你有问题得到一些工作。使用 NSCollectionView 可以让你保留所有当前的 NSView - ,所以它会减少工作。如果它确定,然后你回家&干。如果没有,你还有其他的东西,你可以调整到你的心的内容。

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. Using NSCollectionView lets you keep all your current NSView-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.

这篇关于NSCollectionView与部分 - 如在iPhoto的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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