Inserting Subview Below UICollectionView

隐身守侯 提交于 2019-12-10 20:01:47

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!