未使用重叠的单元格选择来自zIndex的UICollectionView顶部单元格

有钱人

我有一个UICollectionView彼此重叠的单元格。

我将它们设置zIndex在一个UICollectionViewLayout子类中,UICollectionViewLayoutAttributes以便它们在视觉上按所需顺序显示。轻触单元格的重叠区域时zIndex,通过该collectionView:didSelectItemAtIndexPath:方法,触摸平整的击中区域将按预期的方式与较高的单元格一起工作。

我过渡到一个UICollectionViewFlowLayout子类,当我过渡到第一UICollectionViewLayout个子类zIndex时,点击重叠区域时并不总是选择具有较高的单元格

进一步的调查显示,子视图中UICollectionViewCells的顺序UICollectionView正在确定要点击哪个单元格。

我已经编写了一种重新排序子视图的方法,但这似乎有点不合常规。

是否有更好的方法让UICollectionView单元格collectionView:didSelectItemAtIndexPath:根据单元格的外观返回预期的索引路径

奥斯丁

根据我的测试,似乎布局到布局的转换会忽略zIndex推送视图控制器的布局属性。这闻起来像个臭虫。您可以通过在视图控制器出现后重新加载来解决此问题:

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];

    // Reloading will clear selection, so we remember which index paths are selected before reload
    NSArray *selectedIndexPaths = self.collectionView.indexPathsForSelectedItems;
    NSIndexSet *allSections = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, self.collectionView.numberOfSections)];

    [self.collectionView performBatchUpdates:^{

        // First, reload to correct the zOrder
        [self.collectionView reloadSections:allSections];

        // Then, re-select the index paths
        if (selectedIndexPaths.count)
        {
            for (NSIndexPath *indexPath in selectedIndexPaths)
            {
                [self.collectionView selectItemAtIndexPath:indexPath
                                                  animated:YES
                                            scrollPosition:UICollectionViewScrollPositionNone];
            }
        }
    } completion:nil];
}

仍然有点麻烦,但是比手动重新排序集合视图的子视图要少一些麻烦。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章