【发布时间】:2017-05-03 12:42:22
【问题描述】:
我有一个 CollectionView,我动态设置了它的单元格的大小。这是问题所在:当我点击“主页”按钮并再次进入游戏时,CollectionView 会出现问题。所有的细胞看起来都很糟糕,它们的大小不正确并且出现在错误的位置。它只发生在 iPad 上并且在 iPhone 上完美运行。 这是我创建表格的代码:
if collectionView == tableCollectionView{
let cell:TableViewCell = collectionView.dequeueReusableCell(withReuseIdentifier: "letter_cell", for: indexPath) as! TableViewCell
let size = Int(collectionView.frame.size.width) / (lettersCountInRow + 1);
let j = indexPath.row
let i = indexPath.section
let letter = guessLogic!.letters[i * lettersCountInRow + j]
let imageName = String(describing: letter)
let vertical_shift = (Int(collectionView.frame.size.height) - size * 2) / 2
let pad = Double(size) * 0.1;
let start_x = Int(collectionView.frame.size.width) - size*7 - Int(pad) * lettersCountInRow;
cell.letterImage.image = UIImage(named: imageName)
cell.frame = CGRect(x:start_x + j * Int(pad) + j * size, y: i * size + vertical_shift + Int(pad), width: size, height: size)
return cell
}
在 iPad Air-2 上测试
这就是表格的外观: Normal look
这是我按下 HOME 并返回游戏后的样子: Wrong bullsh*t look
【问题讨论】:
-
您能否提供代码如何设置单元格的大小?
-
请添加一些截图。
-
请查看问题中的新信息
标签: ios swift3 uicollectionview