简体   繁体   English

UICollectionView将项目置于中心位置

[英]UICollectionView Bring Item to center position

I have used collectionview to show models as well as years and the user can swipe the cells. 我使用collectionview来显示模型和年份,用户可以刷小区。

The cell which is selected would be positioned to center not depending on number of items. 所选择的单元将被定位到不依赖于项目数量的中心。

Any help would be highly appreciated. 任何帮助将受到高度赞赏。

SOL 1: SOL 1:

collectionView.scrollToItemAtIndexPath(indexPath, atScrollPosition: .centeredHorizontally, animated: true)

SOL 2: I suggest you add empty items at the beginning and end. SOL 2:我建议你在开头和结尾添加空白项目。 So the user can scroll the first and last visible item to the centre. 因此,用户可以将第一个和最后一个可见项滚动到中心。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM