设计带有附加控件的UICollectionView选择的注释 [英] Design for annotating UICollectionView selections with additional controls

查看:63
本文介绍了设计带有附加控件的UICollectionView选择的注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用UICollectionView和StackOverflow此处提供的出色帮助,我已经能够为我的iPhone构建甘特图"样式控件:

Using UICollectionView and excellent help given on here on StackOverflow, I've been able to build a "Gantt Chart" style control for my iPhone:

除了化妆品(我现在正在做功能,我有一名图形设计人员可以查看颜色和所有内容).

Cosmetics aside (I'm doing the functional right now, I've got a graphics designer on tap to look at colors and all that).

,使用自定义UICollectionViewLayout子类进行跨度相对简单.每个跨度都是一个item.

Background aside, the spans were relatively straightforward to do with a custom UICollectionViewLayout subclass. Each span is an item.

但是我需要添加一些功能,并且不确定如何继续.我试图去的地方大致如下所示:

But I need to add some functionality, and am unsure how to proceed. Where I'm trying to go is illustrated roughly as:

撇开粗略的化妆品,重点是我想用其他信息注释"当前选定的跨度(我保证会找人帮我看起来很漂亮).我想让它们处于活动状态,我不确定它是否会带来编辑控件或是否拖动,但是我希望能够识别数字或粗体上的手势并对其进行操作,这与触摸不同驱动选择的范围.

Sketchy cosmetics aside, the point is that I want to "annotate" whatever the currently selected span is with additional information (I promise to find someone to help me look it pretty). And I want them to be active, I'm not sure if it brings up an editing control or does drag, but I want to be able recognize gestures on either the numbers or the bold lines and do things with them, distinct from touching on the span which drives selection.

我至少可以想到3种方法来实现此目的:

I can think of (at least) 3 ways to try and implement this:

  1. 使用补充视图.使选择进入invalidateLayout,检测我的prepareLayout中的选定状态,并为两个锚点生成其他布局属性.实现UICollectionReusableView的子类,该子类进行绘制,并添加可触摸的子视图(或它自己的手势识别器).感觉...不对.我的想法是,补充视图更多地用于页眉和页脚,而不是用于随着选择状态更改而来来去去的控件.但这可能是该功能的适当扩展吗?

  1. Use supplementary views. Cause selection to invalidateLayout, detect the selected state in my prepareLayout, and generate additional layout attributes for the two anchors. Implement a subclass of UICollectionReusableView which does the drawing, and adds touchable subviews (or its own gesture recognizers). This feels... wrong. I get the idea that supplementary views are more for headers and footers, not for controls that come and go as the selection state changes. But maybe it's an appropriate extension of the facility?

使用我当前的SpanCell类(这是UICollectionViewCell的子类)的backgroundView(或selectedBackgroundView,不确定是否重要).只要禁用clipsToBounds,就可以在范围的bounds周围绘制注释.我必须给它一些有关全局的知识以找到端点,但这并不太令人反感.我只是显示/隐藏此视图以响应选择更改.这似乎是最好的方法.

Use the backgroundView (or selectedBackgroundView, not sure it matters) of my current SpanCell class (which is a subclass of UICollectionViewCell). As long as I disable clipsToBounds, I can draw the annotation around the bounds of the span. I'll have to give it some knowledge of the big picture to find the endpoints, but that's not too offensive. I would just show/hide this view in response to selection changes. This seems like the best way to do it.

在整个UICollectionView的主backgroundView中执行此操作.如图所示,我已经有一个专门的backgroundView,它显示了当前的时间网格,带状样式.我可以进一步扩展此视图以绘制注释并响应选择更改来管理可触摸的子控件.这将为我提供最直接的实现,但感觉就像我最终会遇到一个大型怪物为背景做很多工作".

Do it in the main backgroundView of the entire UICollectionView. As shown, I've already got a specialized backgroundView which shows the the current time grid, strip style. I could further extend this view to draw annotations and manage touchable sub controls in response to selection changes. This would give me most direct implementation, but it feels like I'll end up with a big monster "doing too many jobs" object for the background.

那么对于那些有更多经验的人,您会走哪条路线?会是以上3种之一吗?还是有所不同?为什么呢?

Question then, for those who have more experience, is which route would you go? Would it be one of the above 3? Or something different? And why?

推荐答案

虽然您的问题对于UICollectionView实现非常技术性,但我对此并不十分熟悉,但这似乎是容器的一项工作(在这种情况下,集合视图).想象一下,除了所选项目之外,您还需要考虑其他注释吗?例如,要避免注释行和另一个项目之间发生冲突?

While your question is very technical with UICollectionView implementation, which I am not very familiar with, this seems like a job for the container (in this case, the collection view). Imagine you need your annotation to consider, in addition to the selected item, other items? Like for example, avoiding collision between annotation lines and another item?

对我来说,选项3似乎是最正确的选择.如果您担心大型类,可以将其外部化为注释控制器类,每当更新注释时都应通知该类.

For me, option number 3 seems like the most correct one. If you fear a large class, you can extern it to an annotation controller class, which should be notified whenever the annotations should be updated.

这篇关于设计带有附加控件的UICollectionView选择的注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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