【发布时间】:2016-11-14 09:48:52
【问题描述】:
说明:
Objective-C 和 Swift2.0 的答案:How to center align the cells of a UICollectionView?
我通常会尝试将Swift2.0 答案转换为Swift3.0 解决方案,但是方法:
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAtIndex section: Int) -> UIEdgeInsets {
let edgeInsets = (screenWight - (CGFloat(elements.count) * 50) - (CGFloat(elements.count) * 10)) / 2
return UIEdgeInsetsMake(0, edgeInsets, 0, 0);
}
Swift3.0 中似乎不存在,我发现唯一有用的其他方法是:
func collectionView(_ collectionView: UICollectionView, transitionLayoutForOldLayout fromLayout: UICollectionViewLayout, newLayout toLayout: UICollectionViewLayout) -> UICollectionViewTransitionLayout {
<#code#>
}
但我不确定如何正确实施。
问题:
如何在Swift3.0 中将UICollectionView 的单元格居中对齐?
(iOS 和 tvOS 的简单通用解决方案将是完美的)
【问题讨论】: