【发布时间】:2015-03-20 11:28:43
【问题描述】:
我正在尝试创建一个可以容纳不同大小的“视图”等的界面。为此,我正在使用带有这些单元格的 UICollectionView:
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
Card *card = [[[usermanager getSelectedUser] getCards] objectAtIndex:indexPath.item];
UICollectionViewCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:@"cardCell" forIndexPath:indexPath];
[cell addSubview:card];
[cell.layer setBorderColor:[UIColor redColor].CGColor];
[cell.layer setBorderWidth:1.0f];
[cell.layer setMasksToBounds:NO];
return cell;
}
一切似乎都很好,直到卡片数量变得太大而我不得不滚动。当我滚动后抬起手指时,视图会稍微跳跃。我还遇到了一些其他奇怪的 UI 问题。从我读过的内容来看,这与滚动期间重新加载单元格有关。防止这种情况的正确方法是什么?
注意内容是动态的,这一点非常重要。用户应该能够在运行时添加和移除卡片。
谢谢
【问题讨论】:
-
[[usermanager getSelectedUser] getCards]执行需要多长时间? -
你有自己的布局吗?如果是,请确保您继承
UICollectionViewLayout并在使布局无效时使用UICollectionViewLayoutInvalidationContext。 -
@Dennis 我正在使用 CHTCollectionViewWaterFallLayout
-
@trojanfoe 大约 66.0 毫秒
-
@BlackMagic 你是怎么做到的?我正在开发我的应用程序的 iPad 版本,并且在 iPad air 1st gen 上只能获得大约 30-40 fps。使用 cpu 分析器(集合布局除外)没有任何明显的显示。
标签: ios objective-c scroll uicollectionview uicollectionviewcell