我有一个CollectionView,我动态地设置它的单元格的大小。这就是问题所在:当我点击“主页”按钮并再次进入游戏时,CollectionView就崩溃了。所有的单元格看起来都很糟糕,它们的大小错误,并且出现在错误的位置。而且它只在iPads上发生,并且在iPhones上工作得很好。下面是我用于创建表的代码:
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
发布于 2017-05-03 21:06:27
你在viewdidload()中设置了单元格的大小吗?在这种情况下,可以尝试在viewdidappear()中执行此操作,然后查看。
发布于 2017-05-04 16:45:15
好吧,我已经找到解决方案了。这是因为迎新。我禁用了横向,一切都开始完美地工作。
https://stackoverflow.com/questions/43760362
复制相似问题