大型UICollectionViewCell随着自定义布局而消失 [英] Large UICollectionViewCell's disappearing with custom layout

查看:390
本文介绍了大型UICollectionViewCell随着自定义布局而消失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经 UICollectionViewLayout 。到目前为止,这么好。

但是,我有一些比屏幕更宽的单元格,有时这些单元格在滚动时会消失。当你滚动更多时,它们会神奇地再次出现在应有的位置。我可以向你展示我的代码,但我认为它没有任何问题,因为它在90%的情况下有效。但是,真正大的单元格(超过屏幕大小的两倍)有时会消失。

I subclassed UICollectionViewLayout. So far, so good.
However, I have some cells that are wider than the screen, and sometimes these disappear while scrolling. When you scroll some more, they magically reappear where they should be. I can show you my code, however I think there's nothing wrong with it since it works in 90% of the cases.. However, really large cells (more than two times the screen size) disappear sometimes.

NSMutableArray* attributes = [NSMutableArray array];
for (int section=0; section < [[self collectionView] numberOfSections]; section++) {
    [attributes addObject:[self layoutAttributesForSupplementaryViewOfKind:UICollectionElementKindSectionHeader atIndexPath:[NSIndexPath indexPathForItem:0 inSection:section]]];
        for (int row=0; row < [[self collectionView] numberOfItemsInSection:section]; row++) {
            NSIndexPath* indexPath = [NSIndexPath indexPathForItem:row inSection:section];
            [attributes addObject:[self layoutAttributesForItemAtIndexPath:indexPath]];
        }
 }
 return attributes;

我也有这些帖子: UICollectionView的单元格消失 UICollectionView中的大单元格在单元格仍然显示时被删除
但是,没有提到解决方案。任何人都可以帮我吗?这可能是Apple的问题吗?如果是的话,有什么我可以自己解决的吗?

I've also these posts: UICollectionView's cell disappearing and Large cells in a UICollectionView getting removed while the cell is still displayed However, a solution isn't mentioned. Can anybody help me with this? Could it be the problem is on Apple's side? And if it is, is there anything I can do to solve it myself?

推荐答案

很抱歉告诉你:我很漂亮确定这是UICollectionView中的一个真正的错误;几周前我遇到了同样的事情。我已经制作了一个小程序来演示这个bug并向Apple提交了一个RADAR,但是没有回复他们是否计划修复它。我能想到的最好的解决方法(警告:我还没有实现这个解决方法)是要注意布局属性离屏幕边缘很远,故意改变单元格属性的边界,所以它只是略微偏离屏幕,并可能存储该偏移量(您修剪的实际边界应该是多少)作为layoutAttributes中的附加自定义字段,因此您的单元格知道正确地绘制它的内容。这听起来像一个严重的黑客,但它应该工作。

Sorry to tell you: I'm pretty sure this a real bug in UICollectionView; I've run into this exact same thing a few weeks ago. I've made a small program to demonstrate the bug and filed a RADAR with Apple, but haven't heard back on whether or if they plan on fixing it. The best workaround I can think of (Warning: I haven't yet implemented this workaround) is to notice that the layout attributes are very far off the edges of the screen, intentionally change the bounds of the cell attributes so it only slightly goes off screen, and possibly store that offset (the amount that you trimmed off of what the real bounds should be) as an additional custom field in the layoutAttributes, so your cell knows to draw it's content correctly. Which feels like a gross hack, but it ought to work.

这篇关于大型UICollectionViewCell随着自定义布局而消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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