无法移动UICollectionView装饰和补充视图 [英] UICollectionView Decoration and Supplementary views can not be moved

查看:101
本文介绍了无法移动UICollectionView装饰和补充视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

UICollectionView 装饰和补充观点似乎是个大谜。目前似乎没有示例代码。我设法让两种类型都在自定义布局中工作(有关详细信息,请参阅此发布 )。只要它们保持在相同的位置,一切都很好(即,如果它们的 layoutAttributes.frame 没有改变)。

In UICollectionView decoration and supplementary views seem to be a big mystery. There seems to be next to no example code at the moment. I managed to get both types working in a custom layout (see this post for some details). As long as they remain in the same position everything is fine (i.e. if their layoutAttributes.frame does not change).

然而,只要我使用更改的 layoutAttributes 重新布局装饰或补充视图,它们就会在视觉上重复 - 即在背景中有一个副本位于其原始位置,他们新地点的副本。如果我从XIB实例化它们或者完全在代码中实例化它们的行为是相同的,并且正常单元格不会发生这种行为。

However as soon as I re-layout with changed layoutAttributes for either decoration or supplementary views they get visually duplicated - i.e. there is a copy in the background at their original location and a copy at their new location. The behaviour is identical if I instantiate them from XIBs or completely in code and the behaviour does not occur for normal cells.

起初我认为它是某种重绘问题,但这些副本在重新布局,重新绘制等方面都存在。但它们不是真正的副本,因为 layoutAttributesForDecorationView 等从不为它们调用(仅适用于新版本)位置)。在 UICollectionView 的背景中似乎有一些缓存。

At first I thought that it is some kind of redraw problem, but these "copies" survive re-layouting, redrawing etc. They are not real copies however, since the layoutAttributesForDecorationView etc. are never called for them (only for the new locations). There seems to be some caching in the background in the UICollectionView.

有没有人有这个工作或有任何想法。我必须说我是iOS平台的新手,所以它也可以是简单的东西,如设置剪辑绑定或清除图形上下文属性(我试过这些,但它可能是类似的东西)。

Has anybody got this working or have any ideas. I must say that I am new to the iOS platform, so it could also be simple things like setting the "Clips Bound" or "Clear Graphics Context" properties (I tried those, but it could be something similar).

这让我发疯,很奇怪,那里绝对没有示例代码。

This is driving me crazy and it is strange that there is absolutely no example code out there.

我在问自己:装修和补充意见是不是要重新定位? (我希望不会)

I am asking myself: Are the decoration and supplementary views not meant to be repositioned? (I hope not)

推荐答案

这是一个老问题,但有一个答案。

Hi this is an old question but there is an answer for it.

实际上,当我实现自己的Layout对象时,我也遇到了这些问题,直到我意识到必须缓存您在自定义布局中创建的任何布局属性对象。实际上在文档中有一个非常模糊的引用(我现在不记得精确的位置),这很容易被误解。

Actually I had these issues too when I implemented my own Layout object, until I realised it is imperative to cache any layout attributes objects you create in your custom layout. There is actually a very vague reference to this in the documentation (I can't remember the precise location now) which is very easily misinterpreted.

基本上,一旦为索引路径的单元格请求了layoutAttributes对象,就应该保留属性对象(例如,将其保留在索引路径为的字典中) key将执行)并为属性的任何和所有后续请求返回相同的属性对象。如果不这样做,而是重新创建新的布局属性,批量更新的动画会导致严重的图形故障和伪影。

Essentially once you have requested a layoutAttributes object for a cell at an index path, you should retain the attributes object (e.g. retaining it in a dictionary with the index path as a key will do) and return the same attributes object for any and all subsequent requests for the attributes. If you don't do this, but instead recreate new layout attributes, animation of batch updates results in severe graphical glitches and artefacts.

这篇关于无法移动UICollectionView装饰和补充视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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