ric*_*chy 5 iphone z-index objective-c ios uicollectionview
我有UICollectionView
一些相互重叠的细胞.
我将它们设置zIndex
在UICollectionViewLayout
子类中,UICollectionViewLayoutAttributes
因此它们以可视方式显示在所需的顺序中.触摸均匀的命中区域按预期工作,当敲击单元的重叠区域时zIndex
,通过该collectionView:didSelectItemAtIndexPath:
方法具有更高的单元格.
我转换到UICollectionViewFlowLayout
子类,当我转换回第一UICollectionViewLayout
个子类zIndex
时,在点击重叠区域时,并不总是选择具有更高的单元格.
进一步调查显示,子视图中UICollectionViewCell
s 的顺序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];
}
Run Code Online (Sandbox Code Playgroud)
它仍然有点像黑客,但比手动重新排序集合视图的子视图要简单一些。
归档时间: |
|
查看次数: |
2333 次 |
最近记录: |