问题
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.
回答1:
I think
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.
回答2:
Why not just:
[self.collectionView addSubview:self.garmentView];
[self.collectionView insertSubview:self.garmentView belowSubview:self.collectionView];
Are you using storyboard? What member of class is your controller?
来源:https://stackoverflow.com/questions/25353479/inserting-subview-below-uicollectionview