在UICollectionView下面插入子视图 [英] Inserting Subview Below UICollectionView
问题描述
当我在UICollectionView下面添加一个子视图时,有时该子视图显示在UICollectionView单元上方.这是子视图的插入代码:
When I add a subview below a UICollectionView, sometimes the subview shows up above the UICollectionView cells. Here is the subview insertion code:
[self.collectionView insertSubview:self.garmentView atIndex:0];
不确定我是否遵循最佳实践或是否缺少明显的东西.任何帮助表示赞赏.
Not sure if I'm not following a best practice or otherwise missing something obvious. Any assistance appreciated.
**编辑**可能值得注意的是,只有在最右边的单元格被放大时,这种情况才会在横向中发生.
** Edit ** It might be worth noting that this only happens in landscape, when the rightmost cell is zoomed in.
推荐答案
我认为
self.garmentView.layer.zPosition = -1
[self.collectionView insertSubview:self.garmentView atIndex:0];
将解决您的问题.我的猜测是,添加视图单元格的索引可能比服装视图的索引低.请参阅此问题,以更全面地讨论子视图位置.
will solve your problem. My guess is that it can happen that the collection view cells gets added with a lower index than your garmentView. See this question for a more thorough discussion about subview positions.
这篇关于在UICollectionView下面插入子视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!