像这样的代码
collectionLayout.estimatedItemSize = CGSize(width: 50, height: 25)
collectionLayout.itemSize = UICollectionViewFlowLayoutAutomaticSize
collectionLayout.minimumInteritemSpacing = 10
for _ in 0 ..< 1000 {
let length = Int(arc4random() % 8)
let string = randomKeyByBitLength(length)
array.append(string!)
}
collectionView.reloadData()
Run Code Online (Sandbox Code Playgroud)
细胞限制:
当我在iOS 12上运行它时,它是不同的.左模拟器是iOS 11,右边是iOS 12:
但是,当我滚动它时,细胞的帧将是正常的.
我试图理解为什么Collection View保持中心对齐集合中的最后一个单元格.
我创建了一个简单的基于Flow布局的集合视图.我正在使用Autolayout标志 - 我不确定是否会导致此问题.
每当我从Collection视图中删除一个单元格时 - 前几个似乎工作正常并向左滚动.然而,当我移除倒数第二个时,突然最后一个单元从左对齐变为中心对齐.有人有解释吗?这看起来很奇怪.
如何制作它以使所有单元格向左滚动并保持与左对齐.
编辑:这是视图层次调试:http: //imgur.com/a/NxidO
这是视图行为
我已经制作了一个简单的github来演示它:https://github.com/grantkemp/CollectionViewIssue
这是代码:
var dataforCV = ["short","longer phrase", "Super long Phrase"]
override func viewDidLoad() {
super.viewDidLoad()
demoCollectionView.reloadData()
let layout = UICollectionViewFlowLayout()
// Bug Description - > UICollectionViewFlowLayoutAutomaticSize will center Align the layout if it has only a single cell - but it will left align the content if there is more than one cell.
// I would expect this behaviour to be consistently left …Run Code Online (Sandbox Code Playgroud)